Any variable (memory) that can be accessed by more then one thread needs to me mutexed.Anybody could tell me if it should be better if I use a mutex to lock this shared boolean variable when I consult/modify it?
The fact its running well is only a matter of luck.
I once coded an application with 6 threads that would crashed every few days... it was a pain in the a** to find the problem.
With if you have not mutexed shared variables, the behaviour is unpredictable.
But I don't understand why do you use threads in the first place.
You have only two tasks, and one is only done once.
In case the the first task needs to run in parallel to the main thread, then you can do it in a thread, but you can do the other task in the main thread, reducing the complexity of your code dramatically.
Don't use threads unless it is absolutly needed.
Bookmarks