From Bonita Montero@Bonita.Montero@gmail.com to comp.lang.c++ on Wed Apr 2 11:57:44 2025
From Newsgroup: comp.lang.c++
C++ recognizes a thread ID, which is represented by the class thread
::id. Internally, this class has only one data member in libstdc++,
and that is a variable of type pthread_t. However, thread::id recognizes
a default constructed state that does not refer to any thread. I asked
myself how this works, because all possible values of pthread_t can
refer to a thread. This is what the default constructor of thread::id
looks like:
id() noexcept : _M_thread() { }
This means that thread::id::id assumes the default-constructed state of pthread_t as not belonging to any thread. This is actually outside the specification.
Then I was interested in how two thread::id are compared for equality:
/// @relates std::thread::id
inline bool
operator==(thread::id __x, thread::id __y) noexcept
{
// pthread_equal is undefined if either thread ID is not valid, so we
// can't safely use __gthread_equal on default-constructed values (nor
// the non-zero value returned by this_thread::get_id() for
// single-threaded programs using GNU libc). Assume EqualityComparable.
return __x._M_thread == __y._M_thread;
}
This means that pthread_equal is not used as it should be.
--- Synchronet 3.20c-Linux NewsLink 1.2
Who's Online
Recent Visitors
Noozle
Thu Apr 17 18:11:52 2025
from
Noozle City
via
Telnet
Kaptain_Krawdad
Thu Apr 17 17:57:23 2025
from
Southern Il
via
Telnet
Microbot
Thu Apr 17 07:24:59 2025
from
Moore, Ok
via
Telnet
Noozle
Thu Apr 17 06:55:06 2025
from
Noozle City
via
Telnet