C++ Thread, shared data

前端 未结 10 1871
悲&欢浪女
悲&欢浪女 2020-12-04 22:35

I have an application where 2 threads are running... Is there any certanty that when I change a global variable from one thread, the other will notice this change? I don\'t

10条回答
  •  囚心锁ツ
    2020-12-04 23:00

    Chris Jester-Young pointed out that:

    This only work under Java 1.5+'s memory model. The C++ standard does not address threading, and volatile does not guarantee memory coherency between processors. You do need a memory barrier for this

    being so, the only true answer is implementing a synchronization system, right?

提交回复
热议问题