GNU bug report logs - #21887
'monitor' form broken

Previous Next

Package: guile;

Reported by: taylanbayirli <at> gmail.com (Taylan Ulrich Bayırlı/Kammer)

Date: Thu, 12 Nov 2015 15:31:03 UTC

Severity: normal

Done: Andy Wingo <wingo <at> pobox.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: taylanbayirli <at> gmail.com (Taylan Ulrich
 Bayırlı/Kammer)
Subject: bug#21887: closed (Re: bug#21887: 'monitor' form broken)
Date: Mon, 27 Jun 2016 07:34:03 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#21887: 'monitor' form broken

which was filed against the guile package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 21887 <at> debbugs.gnu.org.

-- 
21887: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=21887
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Andy Wingo <wingo <at> pobox.com>
To: 21887-done <at> debbugs.gnu.org
Subject: Re: bug#21887: 'monitor' form broken
Date: Mon, 27 Jun 2016 09:33:36 +0200
thanks

[Message part 3 (message/rfc822, inline)]
From: taylanbayirli <at> gmail.com (Taylan Ulrich Bayırlı/Kammer)
To: bug-guile <at> gnu.org
Subject: 'monitor' form broken
Date: Thu, 12 Nov 2015 16:29:30 +0100
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?


Shameless advertisement: with SRFI-126, the (or (hash-ref ...) ...) bit
would have been just:

    (hashtable-intern! mutex-table uuid make-mutex)

It's borrowed from MIT/GNU Scheme.  Seems pretty useful.

Taylan



This bug report was last modified 8 years and 333 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.