Skip to content

Commit

Permalink
Set PThread::m_isRunning early, when the thread is created.
Browse files Browse the repository at this point in the history
This allows PThread::IsTerminated to return false as soon as the thread
is created, which may be earlier than PThread::PX_ThreadStart manages
to set it. This should fix issues when the code synchronously tests
if the thread is terminated soon after spawning it.
  • Loading branch information
Lastique committed Feb 21, 2022
1 parent d4f29f2 commit 646d25f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ptlib/unix/tlibthrd.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,9 @@ PThread::~PThread()


void * PThread::PX_ThreadStart(void * arg)
{
{
PThread * thread = (PThread *)arg;
SetCurrentThread(thread);
__atomic_store_n(&thread->m_isRunning, true, __ATOMIC_RELAXED);
// Added this to guarantee that the thread creation (PThread::Restart)
// has completed before we start the thread. Then the m_threadId has
// been set.
Expand Down Expand Up @@ -589,6 +588,7 @@ void PThread::Restart()
// create the thread
PAssertPTHREAD(pthread_create, (&m_threadId, &threadAttr, PX_ThreadStart, this));
m_threadIdValid = true;
__atomic_store_n(&m_isRunning, true, __ATOMIC_RELAXED);

// put the thread into the thread list
process.PXSetThread(m_threadId, this);
Expand Down

0 comments on commit 646d25f

Please sign in to comment.