From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.bugs Subject: bug#21887: 'monitor' form broken Date: Fri, 24 Jun 2016 18:04:06 +0200 Message-ID: <87inwyefpl.fsf@pobox.com> References: <87vb97s0bp.fsf@T420.taylan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1466785459 22555 80.91.229.3 (24 Jun 2016 16:24:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 24 Jun 2016 16:24:19 +0000 (UTC) Cc: 21887@debbugs.gnu.org To: taylanbayirli@gmail.com (Taylan Ulrich "=?UTF-8?Q?Bay=C4=B1rl=C4=B1/Kammer?=") Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Fri Jun 24 18:24:02 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 1bGTtc-0001Gp-TQ for guile-bugs@m.gmane.org; Fri, 24 Jun 2016 18:23:57 +0200 Original-Received: from localhost ([::1]:44803 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGTtb-00073R-8Z for guile-bugs@m.gmane.org; Fri, 24 Jun 2016 12:23:55 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33804) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGTbP-0002i1-M0 for bug-guile@gnu.org; Fri, 24 Jun 2016 12:05:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bGTbL-00006p-SP for bug-guile@gnu.org; Fri, 24 Jun 2016 12:05:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42189) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGTbL-000063-MW for bug-guile@gnu.org; Fri, 24 Jun 2016 12:05:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bGTbJ-000782-OA for bug-guile@gnu.org; Fri, 24 Jun 2016 12:05:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andy Wingo Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Fri, 24 Jun 2016 16:05: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.146678425727348 (code B ref 21887); Fri, 24 Jun 2016 16:05:01 +0000 Original-Received: (at 21887) by debbugs.gnu.org; 24 Jun 2016 16:04:17 +0000 Original-Received: from localhost ([127.0.0.1]:54526 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bGTab-000772-9t for submit@debbugs.gnu.org; Fri, 24 Jun 2016 12:04:17 -0400 Original-Received: from pb-sasl1.pobox.com ([64.147.108.66]:61199 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bGTaZ-00076r-ID for 21887@debbugs.gnu.org; Fri, 24 Jun 2016 12:04:15 -0400 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id 2A9981F7BC; Fri, 24 Jun 2016 12:04:14 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; s=sasl; bh=oxhTcTekIoe3 L5FrMY0s+TEdCYY=; b=eAwWCMqNpKvrxmwTCNnLb6S323sG2N8UAUNsNBi77Wjt ihNIVER/EekiVUHpNAz+jLNrx//gbOcPkQE07YTe5KWmY8gPYxpLoPVBaEATdZZj WT4u0LR9d3FCpnFu8jLqZcSRQi//iSNyk7A9bYF5Vwi2arCnEyW15ktg7nX9a00= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; q=dns; s=sasl; b=OnamtM R/yqrXAT2f8wgRoFjvVn7ukBuLeb3BC4T8lZedEgWgVWO8WHaT7xrQy7sn+JSfpO jG+x/438XYQD3t2aE4OrgT23wzymbfrvjNZVCbH2mBD05cLRVacL8Mr2jyJKCykl Br7VNwPv8quD9idFQ+IJbCaRo6AoekbrAxP8M= Original-Received: from pb-sasl1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id 0E44E1F7BB; Fri, 24 Jun 2016 12:04:14 -0400 (EDT) Original-Received: from clucks (unknown [88.160.190.192]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-sasl1.pobox.com (Postfix) with ESMTPSA id 39BFD1F7B9; Fri, 24 Jun 2016 12:04:13 -0400 (EDT) In-Reply-To: <87vb97s0bp.fsf@T420.taylan> ("Taylan Ulrich \"=?UTF-8?Q?Bay=C4=B1rl=C4=B1/Kammer\?=""'s message of "Thu, 12 Nov 2015 16:29:30 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) X-Pobox-Relay-ID: 4B588E04-3A25-11E6-B689-C1836462E9F6-02397024!pb-sasl1.pobox.com 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:8233 Archived-At: Hi Taylan, On Thu 12 Nov 2015 16:29, taylanbayirli@gmail.com (Taylan Ulrich "Bay=C4=B1= rl=C4=B1/Kammer") writes: > It seems that the 'monitor' form is currently a no-op. The form > > (par-for-each (lambda (x) > (monitor > (foo))) > xs) > > should be functionally equivalent to > > (let ((mutex (make-mutex))) > (par-for-each (lambda (x) > (with-mutex mutex > (foo))) > xs)) > > but currently becomes > > (par-for-each (lambda (x) > (let ((mutex (make-mutex))) > (with-mutex mutex > (foo)))) > xs) > > which is ineffective. > > I don't know what's the best way to fix this. The simplest thing that > comes to my mind is something along the lines of: > > (define-syntax monitor > (lambda (stx) > (syntax-case stx () > ((_ body body* ...) > (let ((uuid (generate-uuid))) > #`(with-mutex (mutex-with-uuid #,uuid) > body body* ...)))))) > > where mutex-with-uuid looks it up from a hash table at run-time and > instantiates it when it doesn't exist, this operation also being > synchronized across threads, like: > > (define mutex-table (make-hash-table)) > > (define mutex-table-mutex (make-mutex)) > > (define (mutex-with-uuid uuid) > (with-mutex mutex-table-mutex > (or (hash-ref mutex-table uuid) > (let ((mutex (make-mutex))) > (hash-set! mutex-table uuid mutex) > mutex)))) > > If that looks OK, I can try to make a proper patch from it. I'm not > sure what I'd use in place of `generate-uuid' though. Would `gensym' be > good enough? You're totally right on all points. Please do prepare a patch :) I wish we could do something faster for the "embedded" mutex but correctness should come first. Cheers, Andy