On Tue, 10 Nov 2026 at 13:43, Tomasz Kaminski <[email protected]> wrote: > > > > On Tue, Nov 10, 2026 at 10:50 AM Jonathan Wakely <[email protected]> wrote: >> >> POSIX says that pthread_join() is undefined if the calling thread tries >> to join itself. Our std::thread::join() does not check for this >> (possible because Glibc documents that it will be detected and an error >> reported). >> >> libstdc++-v3/ChangeLog: >> >> PR libstdc++/128548 >> * src/c++11/thread.cc (thread::join): Check for self-join. >> * testsuite/30_threads/thread/members/128548.cc: New test. >> --- >> >> In bugzilla Andrea suggested adding this check to the gthr-posix.h >> version of __gthread_join, as it's already present in (IIRC) the win32 >> and vxworks versions. This seems simpler. > > Yes, seem simpler. But I think it would be better for other projects under GCC > umbrealla (I see it in libfortran), if __gthread_join provides consistient > interface > across platforms. My preference would be to add the test there, and maybe > return EDEADLK consistently.
That's a bit problematic, because not all targets that support gthreads necessarily have EDEADLK, and don't include <errno.h> from their gthr.h today. It would also mean that __gthread_join diverges from pthread_join, which could be confusing. The definition of __gthread_join for VxWorks (see libgcc/config/gthr-vxworks.c) does include a check for self-join today, but it returns "ERROR", not EDEADLK. What is ERROR? I don't know. But it means that std::thread::join() on itself would not throw the correct errc::resource_deadlock_would_occur error, because __gthread_join doesn't return the "correct" error. I think to be reliable, we need std::thread::join() to do the check itself and then be sure it throws the correct error.
