Version française
Home     About     Download     Resources     Contact us    
Browse thread
Mutex and posix
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Brian Hurt <bhurt@s...>
Subject: Re: [Caml-list] Mutex and posix
On Mon, 17 Jan 2005, Alex Baretta wrote:

> > 
> > No, you misunderstand what the function does.  The function won't wait 
> > more than ABSTIME to acquire the lock.  _mutex_lock() waits forever to get 
> > the lock, _mutex_trylock doesn't wait at all, and _mutex_timedlock only 
> > waits so long to get the lock.
> > 
> > Brian
> 
> I am aware of this. But, if one really needs the timed primitive, one 
> can always simulate it by sampling the mutex state repeatedly with 
> _trylock. Unix.select serves the purpose of controlling the sampling time.
> 
> Notwithstanding this, when the need arises for a timed primitive in a 
> concurrent algorithm, my suggestion is always to attempt to remodel the 
> problem rather than the API.

Um, no.  What happens if the mutex is unlocked for some period of time 
between your polls, but relocked before you poll the lock again?  It's 
very easy to hit livelock conditions doing this.

Brian