Opened 11 years ago

Closed 11 years ago

#1067 closed defect (invalid)

Variable set! in signal handler is optimised away in other code.

Reported by: andyjpb Owned by:
Priority: major Milestone: 4.9.0
Component: unknown Version: 4.8.x
Keywords: Cc:
Estimated difficulty:

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.

Change History (4)

comment:1 in reply to:  description Changed 11 years ago by andyjpb

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)))
> 
> ...
> )
)

comment:2 Changed 11 years ago by sjamaan

Milestone: someday4.9.0

We should at least take a look at this one before release

comment:3 Changed 11 years ago by andyjpb

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)));)))

  ))

comment:4 Changed 11 years ago by andyjpb

Resolution: invalid
Status: newclosed

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.

Note: See TracTickets for help on using tickets.