Normally I try to stay away from global variables but it seems like making a mutex variable global makes perfect sense (and then just doing an "extern pthread_mutex_t mutex"). Does anyone forsee any potential problems with this?
Thanks.
Printable View
Normally I try to stay away from global variables but it seems like making a mutex variable global makes perfect sense (and then just doing an "extern pthread_mutex_t mutex"). Does anyone forsee any potential problems with this?
Thanks.
It should work just fine. If you do want to avoid the global variables though, there are ways to do it (without the particular context of the mutex, its hard to say which is best). One option is making the mutex a class member (every instance of the class has its own). It oculd also be a static member, or perhaps a member of a singleton class. It would be easier to keep track of (in my opinion) if you kept the mutex associated with its resource.
Define the global mutex as volatile for multithreading and multiprocesses.
Kuphryn
If you really don't want to use global values like I don't. Then the solution is to use namespaces. This gives you the functionality of a global obejct but lets you put some limits on it.
Then whenever you want to use the value you can because you have the scope but so that you have control of the value you use.Code:namespace theExample
{
// Store the globals in here
}
Hope this helpsCode:
theExample::someValue= 10;