https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89591
Bug ID: 89591
Summary: How can thread.joinable() reliably work if the
pthread_t id is not initialized?
Product: gcc
Version: 8.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: bique.alexandre at gmail dot com
Target Milestone: ---
Hi,
I've been reading the <thread> header and I've found that the thread id of
std::thread is not initialized, I hope that I'm wrong and I missed something.
So I wonder how std::thread.joinable() can work?
On top of that, pthread_t has no "invalid thread id" or "uninitialized thread
id" value. So I wonder how the whole logic can work.
To me if your only attribute is pthread_t, you can't know figure anything about
the thread, and even if the thread exists, there is no guarantee that the
current std::thread object created it: if you create a object: std::thread t;
then t.id will be uninitialized, so could very well point to an existing thread
right?
Regards,
Alex
From the header:
thread() noexcept = default;
and also:
typedef __gthread_t native_handle_type;
/// thread::id
class id
{
native_handle_type _M_thread;
public:
id() noexcept : _M_thread() { }
explicit
id(native_handle_type __id) : _M_thread(__id) { }
private:
friend class thread;
friend class hash<thread::id>;
friend bool
operator==(thread::id __x, thread::id __y) noexcept;
friend bool
operator<(thread::id __x, thread::id __y) noexcept;
template<class _CharT, class _Traits>
friend basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __out, thread::id __id);
};
private:
id _M_id;
and then later:
typedef pthread_t __gthread_t;