English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2005-01-12 (15:56)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: [Caml-list] Mutex and posix
> Just a little question, my curiosity about the thread module.
> I found in Posix (this is from 'info libc' page on section Mutexes) 
> these three functions
> Function: int pthread_mutex_lock (pthread_mutex_t *mutex))
> Function: int pthread_mutex_trylock (pthread_mutex_t *MUTEX)
> Function: int pthread_mutex_timedlock (pthread_mutex_t *MUTEX, const 
> struct timespec *ABSTIME)

The latter is a recent addition to the POSIX threads API -- it's not
in the original POSIX threads spec (POSIX 1003.1c-1995).  I wouldn't
rely on this function being available in all POSIX threads

> Polling continously is different. If I have two threads that are running 
> with scantimes one multiple of the other, it is possible that one of the 
> two threads (the slower one) fails always or almost always the try_lock 
> command.

It's hard to give useful suggestions without knowing more about your
application, but it could be the case that you're using mutexes to do
things they are not really designed for, i.e. plain mutual exclusion,
for which neither trylock nor timedlock are needed.

Maybe your application needs a more complex but better suited
synchronization mechanism, which can generally be built on top of
mutexes and conditions, or (at a higher semantic level) Concurrent
ML-style events.

- Xavier Leroy