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
Usage of condition variables
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-08-18 (03:14)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Usage of condition variables
On Thu, 2006-08-17 at 08:05 +0400, malc wrote:

> <quote>
> The pthread_cond_broadcast() or pthread_cond_signal() functions may be
> called by a thread whether or not it currently owns the mutex that threads
> calling pthread_cond_wait() or pthread_cond_timedwait() have associated
> with the condition variable during their waits; however, if predictable
> scheduling behavior is required, then that mutex shall be locked by the
> thread calling pthread_cond_broadcast() or pthread_cond_signal().
> </quote>
> However it seems like members of OCaml team strongly prefer unlock
> then signal pattern.

When something is predictable, there is often a loss of efficiency
compared to a more indeterminate option.

In this case I'd guess that mutex lock/unlock triggers
a scheduling operation because synchronisation is required
anyhow. If there are multiple signallers it may be more
efficient to delay long enough for the signals to be
collated, and fire off the condition check only once.

John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net