I've got a C++ class containing some class variable like
char some_class::current_command. One of the static methods of this class, say
void Play () now calls the pigpiod
start_thread () method to fork a sub-thread, and then,
current_command is used to control what the thread is doing from the main thread, until it is stopped, of course. The thread needs read-write access to the variable.
As I suspect a race condition leading to unwanted changes of the value of
current_command, I'd like to secure it somehow. Shall I simply use a
std::mutex, or something else, maybe
std::atomic (as demonstrated in answer #1 to this question)? Thank you.