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

前端 未结 7 1470
慢半拍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:32

    Yes it would be better to use synchronization. Any data accessed by multiple threads must be synchronized.

    If it is windows platform you can also check here :Interlocked Variable Access.

提交回复
热议问题