C++ Thread, shared data

前端 未结 10 1866
悲&欢浪女
悲&欢浪女 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 22:59

    Use the volatile keyword to hint to the compiler that the value can change at any time.

    volatile int myInteger;
    

提交回复
热议问题