0

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.

  • 1
    You should ask this on StackOverflow. – Dmitry Grigoryev Mar 18 at 13:27
  • Sorry, but pigpiod is specific to the Raspi…! – Neppomuk Mar 18 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.