I'm trying to implement critical section using objects listed in this article: http://www.mycplus.com/tutorial.asp?TID=290
Somehow, it doesn't work like intended, or maybe I do something wrong. Basically my concept looks like this:
DirectoryReader::DirectoryReader(char* p_sConfigPath)
{
GetConfig(p_sConfigPath);
if( hReaderMutex = CreateMutex( NULL, FALSE, "ReaderMutex") )
cout << "Mutex created!" << endl;
}
DirectoryReader::MakeList(string sPath)
{
While( reading filenames in specified directory )
{
WaitForSingleObject( hReaderMutex, INFINITE );
m_vFilenames.push_back( file name );
ReleaseMutex( hReaderMutex );
}
}
For some reason blocking doesn't work, for example if I call WaitForSingleObject(); right after cerating mutex (it should put semaphore down), I can still access it later in MakeList method. Do I need pass some options in creating mutex? I don't really know how there security attributes work.
Any ideas?
[edit] I want call MakeList() in multiple threads later, I expect problems too. I also don't want use MFC, since I already started project in WIN32, adding MFC class is impossible it seems.