thread::id with libstdc++

Liste des GroupesRevenir à cl c++ 
Sujet : thread::id with libstdc++
De : Bonita.Montero (at) *nospam* gmail.com (Bonita Montero)
Groupes : comp.lang.c++
Date : 02. Apr 2025, 10:57:44
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vsj1m4$1h2bh$1@raubtier-asyl.eternal-september.org>
User-Agent : Mozilla Thunderbird
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.

Date Sujet#  Auteur
2 Apr 25 o thread::id with libstdc++1Bonita Montero

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal