volatile and multithreading?

前端 未结 6 718
被撕碎了的回忆
被撕碎了的回忆 2020-12-06 22:23

In the following code:

#include 
#include 
#include 

pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
int          


        
6条回答
  •  眼角桃花
    2020-12-06 23:16

    I'd be surprised if the compiler assumes anything about a global variable in the presence of library function calls. That being said, volatile will not cost you anything, and it shows your intentions. I'd put it there.

提交回复
热议问题