bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: win32 ost::Mutex class ideology missing


From: David Sugar
Subject: Re: win32 ost::Mutex class ideology missing
Date: Tue, 29 Jun 2004 11:33:11 -0400
User-agent: KMail/1.6.2

I recall we originally did use critical sections, but changed to mutex's, 
although I do not recall why that change was originally done.  If you would 
like to submit a patch that can be controlled by a #define to compile either 
mutex or critical section, that might be the safest immediate solution until 
it can be determined why it was originally changed...

David

On Friday 25 June 2004 09:40 am, Andrey Kulikov wrote:
> 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()".




reply via email to

[Prev in Thread] Current Thread [Next in Thread]