I am looking at a legacy code. I see that there are two DLLs share common code base therefore Dlls shares some common methods and synchronization object name. It means they both create and use a Critical Section synchronization object with the same name. I know global/Static variables are not shared between two modules even within a process on windows. In theory we are creating two independent synchronization objects running independently in their respective DLLs so it shouldn't be a problem.
Now consider this scenario - There is a process Proc.exe which loads two DLLs A.dll and B.dll as mentioned above.Both of these DLLs will have a common critical section object name g_cs and some common method names, for now consider one common method name foo() which is thread safe as following :
foo()
{
....
EnterCriticalSection(g_cs)
....
....
LeaveCriticalSection(g_cs)
....
....
}
Suppose two threads T1 & T2 are running within Proc.exe and are in foo() method currently. Sometimes I observe a deadlock. From the logs I see t1 and t2 simultaneously acquire the critical_section g_cs one after other and never unlock 'g_cs' afterwards. My understanding is that T1 and T2 can simultaneously acquire 'g_cs' only if they are running in context of A.dll and B.dll respectively. Is that is the case then this execution should be safe ?
My understanding is that critical section object belongs to the process so the problem might be because of common name 'g_cs' of synchronization object in two dlls. But theoretically that shouldn't happen.