Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Question on Mutexes
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] Question on Mutexes
> If thread t1 locks mutex m, can thread t2 unlock it?
> I ask because I get no sign of exceptions being thrown when 
> I execute the following code in the toplevel:
> [...]
> Is this a bug or a feature? Are threads supposed to be able 
> to unlock mutexes held by _other_ threads?

No, but this isn't necessarily checked.

The bytecode-level implementation of the thread library doesn't check,
and will actually work correctly if thread A locks the mutex and
thread B unlocks it.  

The system-level implementation of the thread library is a thin
wrapper around POSIX or Win32 mutexes.  The POSIX spec says that the
behavior of unlocking by another thread than the one that locked is
undefined: some implementations can signal an error, others can "do
the right thing", others can crash.

- Xavier Leroy

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: