Question

I have a multi-threaded application. I have three shared resources. Different threads will call those resources simultaneously. I need to have a mutex for that. Will one mutex be enough, or should I create a mutex for every resource? Will it speed up when using many mutexes?

Was it helpful?

Solution

If the resources are independent of eachother, there is no reason to guard them all with a single Mutex. You will be starving other threads of access to resources that they could safely use.

Use one Mutex per resource if possible.

wrt performance - Threads accessing the shared resources are more likely to perform well if the resources are independently guarded as opposed to having a single, shared Mutex - but it depends on many more factors than just this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top