From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: taylanbayirli@gmail.com (Taylan Ulrich =?UTF-8?Q?Bay=C4=B1rl=C4=B1/Kammer?=) Newsgroups: gmane.lisp.guile.bugs Subject: bug#21887: 'monitor' form broken Date: Sat, 25 Jun 2016 16:51:26 +0200 Message-ID: <87wpldgw41.fsf@T420.taylan> References: <87vb97s0bp.fsf@T420.taylan> <87inwyefpl.fsf@pobox.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1466866349 18757 80.91.229.3 (25 Jun 2016 14:52:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 25 Jun 2016 14:52:29 +0000 (UTC) Cc: 21887@debbugs.gnu.org To: Andy Wingo Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Sat Jun 25 16:52:21 2016 Return-path: Envelope-to: guile-bugs@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 1bGowU-0004TJ-66 for guile-bugs@m.gmane.org; Sat, 25 Jun 2016 16:52:18 +0200 Original-Received: from localhost ([::1]:50257 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGowT-0007Cx-CD for guile-bugs@m.gmane.org; Sat, 25 Jun 2016 10:52:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43459) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGowK-0007Cr-5L for bug-guile@gnu.org; Sat, 25 Jun 2016 10:52:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bGowE-0000Is-7E for bug-guile@gnu.org; Sat, 25 Jun 2016 10:52:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:43275) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGowE-0000Io-3W for bug-guile@gnu.org; Sat, 25 Jun 2016 10:52:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bGowD-0005xU-NO for bug-guile@gnu.org; Sat, 25 Jun 2016 10:52:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: taylanbayirli@gmail.com (Taylan Ulrich =?UTF-8?Q?Bay=C4=B1rl=C4=B1/Kammer?=) Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sat, 25 Jun 2016 14:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21887 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 21887-submit@debbugs.gnu.org id=B21887.146686629522873 (code B ref 21887); Sat, 25 Jun 2016 14:52:01 +0000 Original-Received: (at 21887) by debbugs.gnu.org; 25 Jun 2016 14:51:35 +0000 Original-Received: from localhost ([127.0.0.1]:55612 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bGovn-0005wr-JZ for submit@debbugs.gnu.org; Sat, 25 Jun 2016 10:51:35 -0400 Original-Received: from mail-wm0-f68.google.com ([74.125.82.68]:35667) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bGovl-0005wf-Vd for 21887@debbugs.gnu.org; Sat, 25 Jun 2016 10:51:34 -0400 Original-Received: by mail-wm0-f68.google.com with SMTP id a66so12781931wme.2 for <21887@debbugs.gnu.org>; Sat, 25 Jun 2016 07:51:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=qJ2RVOOTRZ5gDH1Q6MGixwWyzkNX7ZChsr2n0kx32Ms=; b=cmjaCwg7j7a2T0f7IWpV58FWsWTsxHHJKXDE+oXI/gyMm6GsZTvFZjpmu/VHC2bhE7 9U41KupzsDos5XJZxMbJm/bYKnL06idaAwo51oFWS2lUZAMb7LuCEL1aoa/9OsQIhrzx 2K2sQrAvADq770z3mpkeoM/7LUhxwK8lZqsYjZVqz4GB6cCcc5FaJmk6mdaI+81WbVH8 Br8AiTaQhDArLVsFp+tPzfYVEUo9e5R9Fkv9vRDgpp6XKgE8c0P0Ltci6xwxHXRBImww V04ch9G1WBEHljrhmbB6QXayymGBo8R/YiMae1lapYkeNwkSkukzlTloEMcfXqkqh/4d 2blg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=qJ2RVOOTRZ5gDH1Q6MGixwWyzkNX7ZChsr2n0kx32Ms=; b=QosNFq/RV4EYak0N9HfflVJWDbdjVKR+7DbadOqLUsXt1QQSe/g7EHXdhcjkQGMzm9 e5nVu5G5qdnu6D8fX4p3NPTLLtiWvL98s8pepsas14oj9J+VD5zdCLbWeRlJmLvqckti 4zioXAh6uJ9Ta0lfjICXc07kwqMWBioWYldGBmJWJPEyns2GveFINPsdocT2qIrkwc2F NipkOW3cYqHjo+legzZQNvWFgYyVnBaP/tmC6Nh5HzHsbK5KylBM5NUhPrYSwWjy+eC1 dVNd6J0Ztl8qY2dNVvseTBhPNo/5PH2oJGCDO/Or9ulSPDTaHEaI1fP7KF1/4IQkP0Sf XoQQ== X-Gm-Message-State: ALyK8tLWYYrwh/evLlgLLJd9Z/LnjVHZPM2D0eiy4FF9z7iVtiXQQgk+QlTFWLTmp5P4NA== X-Received: by 10.28.29.146 with SMTP id d140mr3174767wmd.27.1466866288329; Sat, 25 Jun 2016 07:51:28 -0700 (PDT) Original-Received: from T420.taylan ([2a02:908:c30:3540:221:ccff:fe66:68f0]) by smtp.gmail.com with ESMTPSA id k6sm10317270wjz.28.2016.06.25.07.51.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Jun 2016 07:51:27 -0700 (PDT) In-Reply-To: <87inwyefpl.fsf@pobox.com> (Andy Wingo's message of "Fri, 24 Jun 2016 18:04:06 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.org gmane.lisp.guile.bugs:8248 Archived-At: --=-=-= Content-Type: text/plain Here's a patch, tested minimally by running (par-for-each (lambda (x) (monitor (sleep 1) (display "foo\n"))) (iota 10)) on a quad-core. Previously it would print the "foo"s in groups of four with a second between each group; now it prints them one by one with a second between each, as should be. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Fix-monitor-macro.patch >From 08c7f4cd98c86fbb6551c7c0b6f17262c67e7b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Taylan=20Ulrich=20Bay=C4=B1rl=C4=B1/Kammer?= Date: Sat, 25 Jun 2016 16:43:36 +0200 Subject: [PATCH] Fix 'monitor' macro. * module/ice-9/threads.scm (monitor-mutex-table) (monitor-mutex-table-mutex, monitor-mutex-with-id): New variables. (monitor): Fix it. --- module/ice-9/threads.scm | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/module/ice-9/threads.scm b/module/ice-9/threads.scm index 9f9e1bf..14da113 100644 --- a/module/ice-9/threads.scm +++ b/module/ice-9/threads.scm @@ -85,9 +85,24 @@ (lambda () (begin e0 e1 ...)) (lambda () (unlock-mutex x))))) -(define-syntax-rule (monitor first rest ...) - (with-mutex (make-mutex) - first rest ...)) +(define monitor-mutex-table (make-hash-table)) + +(define monitor-mutex-table-mutex (make-mutex)) + +(define (monitor-mutex-with-id id) + (with-mutex monitor-mutex-table-mutex + (or (hashq-ref monitor-mutex-table id) + (let ((mutex (make-mutex))) + (hashq-set! monitor-mutex-table id mutex) + mutex)))) + +(define-syntax monitor + (lambda (stx) + (syntax-case stx () + ((_ body body* ...) + (let ((id (datum->syntax #'body (gensym)))) + #`(with-mutex (monitor-mutex-with-id '#,id) + body body* ...)))))) (define (par-mapper mapper cons) (lambda (proc . lists) -- 2.8.4 --=-=-=--