Re: dequeue-signal! starts returning signals only after the second is sent

Robert Ransom <[email protected]> Fri, 27 Nov 2009 14:40:12 -0800
Newsgroups gmane.lisp.scheme.scheme48
Message-ID <20091127144012.21b97ad1@neutron>
On Fri, 27 Nov 2009 09:16:26 +0100
Roderic Morris <[email protected]> wrote:

> (dequeue-signal! (make-signal-queue (list (signal chld)))) will return
> signals reliably only after scheme48 recieves the second sigchld. The
> first seems to be ignored, or returned when the second arrives.
> 
> -Roderic
> 

With the attached test script (and the current development revision of
S48), I get the following output:



[rr@neutron ~/tmp]% ~/opt/s48-test-work-2009-11-25-01/bin/scheme48 <s48-signal-test-script-2009-11-27-01.scm 
Welcome to Scheme 48 1.9T (made by rransom on 2009-11-27)
Copyright (c) 1993-2008 by Richard Kelsey and Jonathan Rees.
Please report bugs to [email protected].
Get more information at http://www.s48.org/.
Type ,? (comma question-mark) for help.
> will not prompt and will exit on errors
; no values returned
; no values returned
#{Unspecific}
; no values returned
; no values returned
; no values returned
; no values returned
#{thread 21 signal-reporter}
Done setting up; sleeping for 5 seconds
; no values returned
Sending signal 1 (#{signal cont})
{0}
Sending signal 2 (#{signal chld})
{18}
Got signal: #{signal cont}
Sending signal 3 (#{signal cont})
{17}
Got signal: #{signal chld}
Sending signal 4 (#{signal chld})
{18}
Got signal: #{signal cont}
Sending signal 5 (#{signal cont})
{17}
Got signal: #{signal chld}
#{Unspecific}

[rr@neutron ~/tmp]% 



Looks like the VM os-signal-ring is misbehaving; I'll dig into that
next.

Robert Ransom
s48-signal-test-script-2009-11-27-01.scm (text/x-scheme, 1.4 KB)
,batch
,open posix debug-messages enumerated interrupts threads
,open features
,open (with-prefix srfi-1 srfi-1:)

(define old-sig-handler (get-interrupt-handler (enum interrupt os-signal)))

; arg names copied from scheme/posix/signal.scm os-signal-handler
(define (new-sig-handler os-number enabled-interrupts)
  (debug-message "{" os-number "}")
  (old-sig-handler os-number enabled-interrupts))

(set-interrupt-handler! (enum interrupt os-signal) new-sig-handler)

(define sigq (make-signal-queue (list (signal cont) (signal chld))))
(define me (get-process-id))
(define (sigme sig) (signal-process me sig))

(define (report-signals-indefinitely!)
  (let loop ()
    (let* ((sig (dequeue-signal! sigq))
           (port (current-noise-port)))
      (display "Got signal: " port)
      (display sig port)
      (newline port))
    (loop)))
(spawn report-signals-indefinitely! 'signal-reporter)

(begin
  (display "Done setting up; sleeping for 5 seconds") (newline)
  (force-output (current-output-port))
  (sleep 5000) (values))

(for-each (lambda (i sig)
            (display "Sending signal ") (display i)
            (display " (") (display sig) (display ")") (newline)
            (force-output (current-output-port))
            (sigme sig)
            (sleep 5000))
          '(1 2 3 4 5)
          (srfi-1:circular-list (signal cont)
                                (signal chld)))