Do I need to use locking with integers in c++ threads

前端 未结 7 1466
慢半拍i
慢半拍i 2021-01-04 21:10

If I am accessing a single integer type (e.g. long, int, bool, etc...) in multiple threads, do I need to use a synchronisation mechanism such as a mutex to lock them. My un

相关标签:
7条回答
  • 2021-01-04 21:37

    There's no support for atomic variables in C++, so you do need locking. Without locking you can only speculate about what exact instructions will be used for data manipulation and whether those instructions will guarantee atomic access - that's not how you develop reliable software.

    0 讨论(0)
提交回复
热议问题