unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Mateusz Kowalczyk <fuuzetsu@fuuzetsu.co.uk>
Cc: guile-devel@gnu.org
Subject: Re: Concurrent MVars for Guile
Date: Fri, 17 Jan 2014 19:46:28 -0500	[thread overview]
Message-ID: <874n52qfq3.fsf@netris.org> (raw)
In-Reply-To: <878uuequb2.fsf@netris.org> (Mark H. Weaver's message of "Fri, 17 Jan 2014 14:31:29 -0500")

Mark H Weaver <mhw@netris.org> writes:

> Here's what experiment shows:
>
>   scheme@(guile-user)> (use-modules (ice-9 mvars))
>   scheme@(guile-user)> (define mv (new-empty-mvar))
>   scheme@(guile-user)> (define producers
>                          (map (lambda (i)
>                                 (usleep 200000)
>                                 (call-with-new-thread
>                                   (lambda ()
>                                     (let loop ()
>                                       (put-mvar mv i)
>                                       (loop)))))
>                               (iota 10)))
>   scheme@(guile-user)> (map (lambda (_) (take-mvar mv)) (iota 100))
>   $1 = (0 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8)
>
> I confess that I do not yet understand why the first thread was able to
> put the first two values into the MVar

I see now why that happened.  The first thread was able to immediately
put the first 0 into the MVar without waiting, and then became the first
entry in the wait queue to put the second 0, before the second thread
started waiting to put the first 1.

So, the experiments are perfectly consistent with my understanding from
looking over the code in threads.c, that Guile's mutexes and condition
variables have a FIFO policy for waiting threads.  Therefore my MVar
implementation also has a FIFO policy, and therefore meets the fairness
requirements.

      Mark



  reply	other threads:[~2014-01-18  0:46 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-02  7:55 Concurrent MVars for Guile Mark H Weaver
2013-09-03 11:55 ` Mark H Weaver
     [not found]   ` <CAGua6m3o_NexANbGuDYd5_rbPQqsbXkK504ONaFE7PGdQd98og@mail.gmail.com>
2013-09-04  6:27     ` Fwd: " Stefan Israelsson Tampe
2013-09-05  2:10 ` David Thompson
2013-09-05  2:53   ` Mark H Weaver
2013-09-14 13:59 ` Ludovic Courtès
2013-09-17 20:18   ` Andy Wingo
2014-01-16  0:47     ` Mark H Weaver
2014-01-16 13:01       ` Ludovic Courtès
2014-01-17  6:33 ` Mateusz Kowalczyk
2014-01-17 19:31   ` Mark H Weaver
2014-01-18  0:46     ` Mark H Weaver [this message]
2014-01-18  1:05     ` Mateusz Kowalczyk
2014-01-21  5:38       ` Mark H Weaver

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

  List information: https://www.gnu.org/software/guile/

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

  git send-email \
    --in-reply-to=874n52qfq3.fsf@netris.org \
    --to=mhw@netris.org \
    --cc=fuuzetsu@fuuzetsu.co.uk \
    --cc=guile-devel@gnu.org \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).