Summary
Variable set! in signal handler is optimised away in other code.
Metadata
- Id: 0ddf605c64202326c6e2df8a09b1bac811a5b26e
- Trac id: 1067
- Type: defect
- Reporter: andyjpb
- Owner:
- Cc:
- Status: closed
- Component: unknown
- Estimated difficulty:
- Resolution: invalid
- Priority: major
- Milestone: 4.9.0
- Version: 4.8.x
- Changetime: 2014-01-19 14:07:18 UTC
- Created: 2013-11-19 18:20:26 UTC
- Keywords:
Description
In a module I have
(define keep-going "yes") ; #t seems to cause the (if keep-going ...) check to get optimised away.
...
(define (shutdown #!optional signum)
(debug! "Proclaim got signal ~A: shutting down..." signum)
(set! keep-going #f))
(define (handler)
(set-signal-handler! signal/term shutdown)
...
(if keep-going
(begin
...
(loop)))
...
)
In my main program I (use ...) my module and then call handler which loops "forever".
As per the comment, if I use #t for the sentinel value of keep-going then the signal handler is unable to set! it to #f so the loop is never broken. If I use "yes" then it seems to work as expected.
I can't use a parameter because I don't know which thread the signal will be received in and the loop runs in the primordial thread.
Changes and comments
[2013-11-19 18:25:44 UTC] andyjpb wrote:
Everything is in the same module:
(module ... > (define keep-going "yes") ; #t seems to cause the (if keep-going ...) check to get optimised away. > > ... > > (define (shutdown #!optional signum) > (debug! "Proclaim got signal ~A: shutting down..." signum) > (set! keep-going #f)) > > (define (handler) > (set-signal-handler! signal/term shutdown) > > ... > > (if keep-going > (begin > ... > (loop))) > > ... > ) )
[2013-12-09 16:00:43 UTC] sjamaan changed milestone from someday to 4.9.0
[2013-12-09 16:00:43 UTC] sjamaan wrote:
We should at least take a look at this one before release
[2013-12-15 17:34:14 UTC] andyjpb wrote:
Here's a self contained program that should reproduce the behaviour, but I can't currently get it to work.
; csc -s -O2 -d1 t.scm -j t -o t.so ; csc -s t.import.scm -O2 -d0 -o t.import.so ; echo "(use t)(handler)" > tl.scm ; csc tl.scm ; ./tl ; killall -TERM tl (module t (handler) (import chicken scheme) (use posix srfi-18) (define keep-going #t) ; #t seems to cause the (if keep-going ...) check to get optimised away. (define (shutdown #!optional signum) (printf "Proclaim got signal ~A: shutting down...\n" signum) (set! keep-going #f)) (define (handler) (set-signal-handler! signal/term shutdown) ;(thread-start! ; (make-thread ; (lambda () (let loop () (printf "Still going...\n") (thread-sleep! 1) (if keep-going (loop)));))) ))
[2014-01-19 14:07:18 UTC] andyjpb changed status from new to closed
[2014-01-19 14:07:18 UTC] andyjpb set resolution to invalid
[2014-01-19 14:07:18 UTC] andyjpb wrote:
Now that it comes to test a fix, I can't seem to reproduce this at all. :-(
For now I'll mark it as INVALID but I'll keep a look out for it in the future.