Since I was experiencing threads-related problems when updating grids widgets, I am wondering what is the simplest solution to avoid data corruption when multiple threads modify/read widgets data.
I am reading some C++ 11 book, it says std::mutex/std::recursive mutex is a decent solution to my problem, so is stick to wxWidgets in-build thread functions a better solution since the in-build wrapper/helper functions should be more noob-friendly?
Thanks again.
Questions regarding threads in wxWidgets
-
- Experienced Solver
- Posts: 81
- Joined: Wed Oct 19, 2016 1:41 pm
Re: Questions regarding threads in wxWidgets
You should not update UI-elements from threads (please repeat this inside your head 1000 times!). You should post messages from the threads to the main message loop in order to update the grid. In order to prevent multiple thread accessing the same code / memory at once you should use a wxCriticalSection (and a wxCriticalSectionLocker):
http://docs.wxwidgets.org/3.1/classwx_c ... ction.html
http://docs.wxwidgets.org/3.1/classwx_c ... ocker.html
Mutex'es are a heavier instrument than critical sections. Mutex'es should only be used in a environment where multiple processes may access the same resource.
http://docs.wxwidgets.org/3.1/classwx_c ... ction.html
http://docs.wxwidgets.org/3.1/classwx_c ... ocker.html
Mutex'es are a heavier instrument than critical sections. Mutex'es should only be used in a environment where multiple processes may access the same resource.
I have a bad habbit of not testing the code I post
-
- Experienced Solver
- Posts: 81
- Joined: Wed Oct 19, 2016 1:41 pm
Re: Questions regarding threads in wxWidgets
Thanks for the tips. Is the usage of such multi-thread functions covered in wxwidgets "thread" example/sample source code? or I could find similar content in wiki or on this site?DenDev wrote:You should not update UI-elements from threads (please repeat this inside your head 1000 times!). You should post messages from the threads to the main message loop in order to update the grid. In order to prevent multiple thread accessing the same code / memory at once you should use a wxCriticalSection (and a wxCriticalSectionLocker):
http://docs.wxwidgets.org/3.1/classwx_c ... ction.html
http://docs.wxwidgets.org/3.1/classwx_c ... ocker.html
Mutex'es are a heavier instrument than critical sections. Mutex'es should only be used in a environment where multiple processes may access the same resource.
-
- Earned some good credits
- Posts: 138
- Joined: Tue May 20, 2008 1:03 pm
Re: Questions regarding threads in wxWidgets
May be you can use this post viewtopic.php?f=1&t=39098&p=158185#p158181 or this one viewtopic.php?f=1&t=42670
L.B.