[Top][All Lists]
[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: |
Fri, 25 Jun 2004 09:22:00 -0400 |
User-agent: |
KMail/1.6.2 |
Recursive also means that the mutex is not unlocked for other threads until
the same number of unlock requests are made as locks. That is different from
simply "ignored" since the mutex would then be freed on the first unlock if
the additional locks from the same thread are ignored.
It could be possible to create a simple test case where a mutex is locked
twice, and then a child thread is created. The parent sleeps for a bit to
give the child a chance to run, and the child tries to lock the same mutex.
The parent then unlocks one and then sleeps to give the child a chance to run
again. Then the parent unlocks the second time. The child should print
something immediately after aquiring the mutex which should (on a recursive
mutex) only happen after the second unlock. This would show if it is
recursive or if it simply ignores.
On Friday 25 June 2004 06:04 am, Andrey Kulikov wrote:
> Hello David,
>
> DS> I do not recall offhand, but are critical sections recursive?
>
>
> As i understand, recursive means that one thread can lock
> synchronization object only once, and following next attempts to lock
> in the same thread will be ignored.
> (Ok, not ignored, but deadlock will be avoided).
>
> With my changes in ost::Mutex this program
> ==============================
> #include "stdafx.h"
> #include <cc++/thread.h>
> #include <iostream>
>
> using namespace std;
>
> int _tmain(int argc, _TCHAR* argv[])
> {
> ost::Mutex mtx;
>
> cout << "1" << endl;
> mtx.enterMutex();
> cout << "2" << endl;
> mtx.enterMutex();
> cout << "3" << endl;
> mtx.leaveMutex();
> cout << "4" << endl;
> mtx.leaveMutex();
> cout << "5" << endl;
> return 0;
> }
> ==============================
>
> Produces output
> ==============================
> 1
> 2
> 3
> 4
> 5
> ==============================
>
> i.e. deadlock by second enterMutex in the same thread not appears.
>
> Is this correct?