maybe-commit-and-make-ready-and-block

Taylor R Campbell <[email protected]>
Newsgroups gmane.lisp.scheme.scheme48
Message-ID <[email protected]>
It would be nice if Scheme48 had a procedure that would atomically (1)
maybe commit the current proposal, (2) make a thread or a queue of
threads ready, and (3) block on a cell.  That way, it would not be
impossible to correctly implement an operation to atomically unlock a
mutex (other than a spin mutex) and wait on a condition variable.  The
definition would look something like this:

(define (maybe-commit-and-block-and-make-ready cell thread-or-queue)
  (disable-interrupts!)
  (cond ((maybe-commit)
         (if (queue? thread-or-queue)
             (make-threads-ready thread-or-queue)
             (make-ready thread-or-queue))
         (set-thread-cell! (current-thread) cell)
         (suspend-to (thread-scheduler (current-thread))
                     (list (enum event-type blocked)))
         #t)
        (else
         (enable-interrupts!)
         #f)))

However, just calling MAKE-THREADS-READY or MAKE-READY as-is breaks
down here, because those call MAYBE-SUSPEND, rendering the operation
non-atomic.

Also, for unrelated reasons, it would be nice if this operation (and
all the MAYBE-COMMIT-AND-* operations: MAYBE-COMMIT-AND-BLOCK, &c.)
left the enabled interrupts alone if the commit failed, rather than
enabling all interrupts.  This is what MAYBE-COMMIT-NO-INTERRUPTS
already does.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.