Saturday, June 8, 2013

How to notify outside thread of main thread state without using global variables?

How to notify outside thread of main thread state without using global variables?

Say i have main thread and it is running my win32 procedure and a few worker threads to carry out functions that are clicked on by the user.
Lets say there is a change in the main function (I want 1 button to be available while another one is not, but only when the program enters a certain state (i.e by a boolean trigger or something of that nature), and notify all running threads that i want to disable to terminate?)?
Passing arguments to the thread only captures the state of the main thread at a certain point in time. What if i want to monitor the state of my main thread across different time frames or events?
I currently have a few global boolean values to flag/signal the program's current mode or state and that is how i notify the worker threads in how they should change their behavior.
Should I eliminate my use of global variables or keep them? Or if i should eliminate the global varialbes, how would i reimplement my program?