caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] recursive mutexes?
@ 2002-11-08 15:20 Basile STARYNKEVITCH
  2002-11-11  9:55 ` Xavier Leroy
  0 siblings, 1 reply; 2+ messages in thread
From: Basile STARYNKEVITCH @ 2002-11-08 15:20 UTC (permalink / raw)
  To: caml_list

Dear All,

Does the Mutex module allow "recursive" mutexes, so can I code
something like

let mylock = Mutex.create ();;

let innerf () =
   Mutex.lock mylock;
   Printf.printf "in innerf\n";
   Mutex.unlock mylock
;;

let f () = 
    Mutex.lock mylock;
    (* do something complicated, then ... *)
    innerf ();
    Mutex.unlock mylock
;;

I expect that the lock in innerf always succeed, since mylock is
already locked by the same thread in the caller function f. Am I right
in thinking so?  (the reference manual is not fully clear on this, and
it is an important point).

FWIW my plateform is Linux/x86 with pthreads but I would like a
"definitive" statement from our Inria team on this point.

AFAIK some Posix threads accept recursive locking.

regards.
-- 

Basile STARYNKEVITCH         http://starynkevitch.net/Basile/ 
email: basile<at>starynkevitch<dot>net 
alias: basile<at>tunes<dot>org 
8, rue de la Faïencerie, 92340 Bourg La Reine, France
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] recursive mutexes?
  2002-11-08 15:20 [Caml-list] recursive mutexes? Basile STARYNKEVITCH
@ 2002-11-11  9:55 ` Xavier Leroy
  0 siblings, 0 replies; 2+ messages in thread
From: Xavier Leroy @ 2002-11-11  9:55 UTC (permalink / raw)
  To: Basile STARYNKEVITCH; +Cc: caml_list

> Does the Mutex module allow "recursive" mutexes

No.  A thread blocks forever if it attempts to lock a mutex it already
locked before.

> (the reference manual is not fully clear on this, and
> it is an important point).

I agree the documentation should be clearer on this point.

> AFAIK some Posix threads accept recursive locking.

Some do, but the POSIX 1003.1c standard specifies non-recursive
mutexes only.  There are endless arguments on the usefulness/evilness
of recursive mutexes on comp.programming.threads; the jury is still
out on this one.  

Of course, it is not difficult to implement recursive mutexes yourself
on top of normal mutexes.  You won't be able to use your recursive
mutexes in conjunction with condition variables, though.

- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-11-12  8:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-08 15:20 [Caml-list] recursive mutexes? Basile STARYNKEVITCH
2002-11-11  9:55 ` Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).