In the following code:
#include #include #include pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; int
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.