A simple situation here,
If I got three threads, and one for window application, and I want them to quit
when the window application is closed, so is it thread-safe if I use one global variable,
so that three threads will quit if only the global variable is true, otherwise continue its work?
Does the volatile help in this situation?
C++ programming.
A simple situation here, If I got three threads, and one for window application,
Share
If you only want to “read” from the shared variable from the other threads, then it’s ok in the situation you describe.
Yes the volatile hint is required or the compiler might “optimize out” the variable.
Waiting for the threads to finish (i.e.
join) would be good too: this way, any clean-up (by the application) that should occur will have a chance to get done.