From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Re: Concurrent MVars for Guile Date: Fri, 17 Jan 2014 19:46:28 -0500 Message-ID: <874n52qfq3.fsf@netris.org> References: <87fvtn1wv8.fsf@tines.lan> <52D8CEC6.9080800@fuuzetsu.co.uk> <878uuequb2.fsf@netris.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1390006148 22304 80.91.229.3 (18 Jan 2014 00:49:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 18 Jan 2014 00:49:08 +0000 (UTC) Cc: guile-devel@gnu.org To: Mateusz Kowalczyk Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Jan 18 01:49:14 2014 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1W4K66-0004ax-Hz for guile-devel@m.gmane.org; Sat, 18 Jan 2014 01:49:14 +0100 Original-Received: from localhost ([::1]:40789 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4K66-0004rJ-3t for guile-devel@m.gmane.org; Fri, 17 Jan 2014 19:49:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51483) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4K5x-0004r8-FJ for guile-devel@gnu.org; Fri, 17 Jan 2014 19:49:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W4K5r-0006HN-9i for guile-devel@gnu.org; Fri, 17 Jan 2014 19:49:05 -0500 Original-Received: from world.peace.net ([96.39.62.75]:52882) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4K5r-0006H6-1P for guile-devel@gnu.org; Fri, 17 Jan 2014 19:48:59 -0500 Original-Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=yeeloong) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1W4K5h-0003xB-Mm; Fri, 17 Jan 2014 19:48:49 -0500 In-Reply-To: <878uuequb2.fsf@netris.org> (Mark H. Weaver's message of "Fri, 17 Jan 2014 14:31:29 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 96.39.62.75 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:16815 Archived-At: Mark H Weaver 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