wxThread->Delete() - Exception thrown: read access violation. Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
tuk1
Earned some good credits
Earned some good credits
Posts: 114
Joined: Sun Oct 08, 2017 9:36 am

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by tuk1 »

Just to confirm once upgraded to 3.1.3, no more errors when rapidly clicking buttons to start/stop threads.

...& the new skins look nice, looking forward to 3.1.4
wxWidgets(v3.2.2.1) - Vs2022(v143) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7481
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by ONEEYEMAN »

Hi,
Looks like the release already been done. ;-)

Thank you.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by PB »

Just for the future reference (I always use the similar code for worker and GUI threads communication example): It took me almost two years, but I finally figured out why the code crashes with wxWidgets 3.0 but not 3.1.

It is due to a difference in wxThread::Delete() call, which means wxThread::Delete(NULL, wxTHREAD_WAIT_DEFAULT).

Unlike wxWidgets 3.1, wxWidgets 3.0 has by default WXWIN_COMPATIBILITY_2_8 set. When WXWIN_COMPATIBILITY_2_8 is set, wxTHREAD_WAIT_DEFAULT evaluates to wxTHREAD_WAIT_YIELD, but when it is not set, it evaluates to wxTHREAD_WAIT_BLOCK.

As documented, wxTHREAD_WAIT_YIELD is dangerous because it allows processing events even while the thread is being deleted, which led to the crashes reported in this thread.

So in wxWidgets 3.0 (or whenever WXWIN_COMPATIBILITY_2_8 is set), one should not use just

Code: Select all

m_dataLoadingThread->Delete();
but instead

Code: Select all

m_dataLoadingThread->Delete(NULL, wxTHREAD_WAIT_BLOCK);
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7481
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by ONEEYEMAN »

PB,
Time for another issue?

Thank you.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxThread->Delete() - Exception thrown: read access violation.

Post by PB »

ONEEYEMAN wrote: Thu Feb 03, 2022 4:57 am Time for another issue?
No, it was my error, I did not RTFM.
Post Reply