Pregunta

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?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top