[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re[2]: win32 ost::Mutex class ideology missing
From: |
Andrey Kulikov |
Subject: |
Re[2]: win32 ost::Mutex class ideology missing |
Date: |
Fri, 25 Jun 2004 17:40:46 +0400 |
Hello David,
Friday, June 25, 2004, 5:22:00 PM, you wrote:
DS> Recursive also means that the mutex is not unlocked for other threads until
DS> the same number of unlock requests are made as locks. That is different
from
DS> simply "ignored" since the mutex would then be freed on the first unlock if
DS> the additional locks from the same thread are ignored.
DS> It could be possible to create a simple test case where a mutex is locked
DS> twice, and then a child thread is created. The parent sleeps for a bit to
DS> give the child a chance to run, and the child tries to lock the same mutex.
DS> The parent then unlocks one and then sleeps to give the child a chance to
run
DS> again. Then the parent unlocks the second time. The child should print
DS> something immediately after aquiring the mutex which should (on a recursive
DS> mutex) only happen after the second unlock. This would show if it is
DS> recursive or if it simply ignores.
Yes, it exacly what i mean under "ignored"
This is a test.
Program:
=======================================================
#include <cc++/thread.h>
#include <iostream>
using namespace std;
ost::Mutex mtx;
class TestLockThread : public ost::Thread
{
protected:
virtual void run(void){
cout << "TH 1" << endl;
mtx.enterMutex();
cout << "TH 2" << endl;
mtx.leaveMutex();
};
};
int _tmain(int argc, _TCHAR* argv[])
{
cout << "1" << endl;
mtx.enterMutex();
cout << "2" << endl;
mtx.enterMutex();
TestLockThread tlt;
tlt.start();
ost::Thread::sleep(1500);
cout << "3" << endl;
mtx.leaveMutex();
ost::Thread::sleep(500);
cout << "4" << endl;
ost::Thread::sleep(500);
mtx.leaveMutex();
ost::Thread::sleep(500);
cout << "5" << endl;
return 0;
}
=======================================================
Output:
=======================================================
1
2
TH 1
3
4
TH 2
5
=======================================================
I.e. child thread continue execution only after parent's second
"leaveMutex()".
--
Best regards,
Andrey mailto:address@hidden