c++ - Different Between Static Mutext and Not Static Mutex -


i have code in .cpp

namespapce {     namespace     {         static cmutex initmutex;     }      void init()     {         //code here     }      void uninit()     {         //code here     } } 

what different if remove static in mutex , if there static? , use of static?

thanks!

if mutex static , if have been in header , header included in 2 cpp files(2 translational units), lock applied code in first file not seen second file dangerous. because 2 units has separate static of mutex. in case global mutex preferable.

if c++ use raii mechanism manage mutex lock , unlock. c++, class? encapsulate things class.

raii example (basic one, things can encapsulated class): http://en.wikipedia.org/wiki/resource_acquisition_is_initialization


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -