Skip to main content
corrected spelling
Link
quamrana
  • 39.5k
  • 13
  • 57
  • 77

c++ volatile multithreading varaiblesvariables

Fix tag typo
Link
Paul R
  • 214.1k
  • 38
  • 402
  • 579
Source Link
anon
  • 43.1k
  • 54
  • 204
  • 300

c++ volatile multithreading varaibles

I'm writing a C++ app.

I have a class variable that more than one thread is writing to.

In C++, anything that can be modified without the compiler "realizing" that it's being changed needs to be marked volatile right? So if my code is multi threaded, and one thread may write to a var while another reads from it, do I need to mark the var volaltile?

[I don't have a race condition since I'm relying on writes to ints being atomic]

Thanks!