TBB mutex not safe in Windows shared DLL?

TBB mutex not safe in Windows shared DLL?

I have heard that the mutex object simply uses Critical Sections in Win32. This is very fast for a
process, but isn't safe in a DLL that is used by multiple processes.

Is this true?

2 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.
Portrait de robert-reed (Intel)

Yes, TBB::mutex object uses Enter|LeaveCriticalSection in the Windows implementation and pthread_mutex_lock|unlock otherwise. Each of these are meant to operate within a process, avoiding the overhead incurred for interprocess communication.

So what about shared DLLs? While the "text" of a shared DLL (the instructions and constants parts) are shared among processes, the "data" part is not. Each belongs to the respective process. In fact, you have to go to some extremesto share memory between multiple instantiations of a DLL. It's possible and there certainly are DLLs out there that use shared memory to moderate communications between multiple processes, but this is not the norm.

So, if you use tbb::mutex in a DLL that only uses parent process data, you should not have to worry about thread safety issues using tbb::mutex. But if you're DLL is moderating between multiple processes, the data structures involved will need stronger (slower) protections.

Connectez-vous pour laisser un commentaire.