Overview
Features
Download
Documentation
Community
Add-Ons & Services

Deadlock in RWLockImpl?

Please post support and help requests here.

Deadlock in RWLockImpl?

Postby buaaji » 07 Feb 2014, 07:59

I'm using POCO 1.4.6p1, and I suspect the RWLockImpl can lead to deadlock.

The major problem is that the data member _mutex is a Mutex which actually should be an auto Event, and it has a very important concept which is called ownership in Mutex. Below is the sample code to simply reproduce the deadlock...

HANDLE globalLock;
HANDLE event0;
HANDLE event1;

DWORD WINAPI func(LPVOID lpThreadParameter )
{
::Sleep(1000);
HANDLE sets[] = {globalLock, event1};
::WaitForMultipleObjects(2, sets, TRUE, INFINITE);
cout<< "Thread 2"<<endl;
return 0;
}

int _tmain (int argc , _TCHAR * argv [])
{
//globalLock = :: CreateEvent (NULL , FALSE , TRUE , NULL ); // An auto event, no deadlock
globalLock = :: CreateMutex( NULL, FALSE, NULL); // A mutex, deadlock...
event0 = :: CreateEvent (NULL , TRUE , FALSE , NULL );
event1 = :: CreateEvent (NULL , TRUE , TRUE , NULL );

::CreateThread( NULL, 0, func, NULL, 0, NULL);

HANDLE sets[] = {globalLock, event0};
::WaitForMultipleObjects(2, sets, TRUE, INFINITE);

return 0;
}
buaaji
 
Posts: 4
Joined: 06 Apr 2011, 16:14

Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests