Changes between Version 1 and Version 5 of Ticket #18137


Ignore:
Timestamp:
Jul 6, 2018, 3:48:51 PM (2 years ago)
Author:
vadz
Comment:

I think you're right and SuspendThread() is indeed async. However this means that we basically can't ensure that the thread doesn't get suspended inside a CS, so nothing can be done about it...

Unless we use the trick mentioned in Raymond Chen's post above and call GetThreadContext(). So what about the following patch instead?

  • src/msw/thread.cpp

    diff --git a/src/msw/thread.cpp b/src/msw/thread.cpp
    index 0805e1e19a..5c94613f46 100644
    a b bool wxThreadInternal::Suspend() 
    875875        return false;
    876876    }
    877877
     878    // Calling GetThreadContext() forces the thread to actually be suspended:
     879    // just calling SuspendThread() is not enough, it just asks the scheduler
     880    // to suspend the thread at the next opportunity and by then we may already
     881    // exit wxThread::Pause() and leave m_critsect, meaning that the thread
     882    // could enter it and end up suspended inside a CS, which will inevitably
     883    // result in a deadlock later.
     884    CONTEXT ctx;
     885    // We don't really need the context, but we still must initialize it.
     886    ctx.ContextFlags = CONTEXT_FULL;
     887    if ( !::GetThreadContext(m_hThread, &ctx) )
     888    {
     889        wxLogLastError(wxS("GetThreadContext"));
     890    }
     891
    878892    m_state = STATE_PAUSED;
    879893
    880894    return true;

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #18137

    • Property Status changed from closed to reopened
    • Property Resolution changed from invalid to
  • Ticket #18137 – Description

    v1 v5  
    2424
    2525[1] Call stack of my wxThread worker
     26{{{
    2627        ntdll.dll!RtlpAllocateHeap()    Unknown
    2728        ntdll.dll!RtlAllocateHeap()     Unknown
     
    4344        kernel32.dll!BaseThreadInitThunk()      Unknown
    4445        ntdll.dll!RtlUserThreadStart()  Unknown
    45 
     46}}}
    4647
    4748[2] Call stack of the main thread:
     49{{{
    4850        ntdll.dll!NtWaitForSingleObject()       Unknown
    4951        ntdll.dll!RtlpWaitOnCriticalSection()   Unknown
     
    6062        graph64.exe!MainWindow::OnStop(wxCommandEvent & __formal) Line 515      C++
    6163....
    62 ....
     64}}}