caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: malc <malc@pulsesoft.com>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Usage of condition variables
Date: Thu, 17 Aug 2006 13:55:50 +0200	[thread overview]
Message-ID: <44E45946.3090102@inria.fr> (raw)
In-Reply-To: <Pine.LNX.4.64.0608170749530.631@home.oyster.ru>

> [Use of condition variables]
> However it seems like members of OCaml team strongly prefer unlock
> then signal pattern. Given that Xavier Leroy is also the author of
> LinuxThreads there might be some good arguments to have it that way,
> or maybe it's because of vmthreads, perhaps someone could give the
> rationale?

That's an old debate -- I've seen threads of 100+ messages on this
topic back in the days when I read comp.programming.threads.

My take on this is that both patterns are correct if your program is
reasonable, i.e. no real-time scheduling with priorities, and all uses
of Condition.wait are protected against spurious wakeups (as they
should always be).

Moreover, the "unlock then signal" variant is slightly more efficient
with naive thread implementations such as LinuxThreads, because
"signal then unlock" can cause threads waiting on the condition to be
restarted only to block immediately on the mutex.  (More sophisticated
implementations can avoid this by clever manipulations of wait queues.)

Butenhof's book on POSIX threads probably contains a better discussion
of the issue.

- Xavier Leroy


      parent reply	other threads:[~2006-08-18 15:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-17  4:05 malc
2006-08-17  7:41 ` [Caml-list] " skaller
2006-08-17 11:55 ` Xavier Leroy [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44E45946.3090102@inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=malc@pulsesoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).