summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2017-01-08 14:15:54 +0100
committerAndy Wingo <wingo@pobox.com>2017-01-08 14:15:54 +0100
commit6bd9453999fd1c4bccf3a83e17bef2bf3020c8cc (patch)
treeabba87f5f43e93ea9de87f5276cd0dd1c3fa4b6a
parentFix clock-nanosleep wrapper (diff)
downloadguile-fibers-6bd9453999fd1c4bccf3a83e17bef2bf3020c8cc.tar.gz
Fix race between with-interrupts and thread start
* fibers/interrupts.scm (with-interrupts/thread-cputime): Fix race.
-rw-r--r--fibers/interrupts.scm14
1 files changed, 10 insertions, 4 deletions
diff --git a/fibers/interrupts.scm b/fibers/interrupts.scm
index 10f64aa..9800877 100644
--- a/fibers/interrupts.scm
+++ b/fibers/interrupts.scm
@@ -51,10 +51,16 @@
(set! interrupt-thread
(call-with-new-thread
(lambda ()
- (let lp ()
- (clock-nanosleep clockid period-nsecs)
- (system-async-mark interrupt target-thread)
- (lp)))))))
+ ;; It's possible that the thread has already exited
+ ;; before we start, and the clock-nanosleep fails
+ ;; directly. Or who knows what happens when the target
+ ;; thread dies during the nanosleep? Anyway just wrap
+ ;; the whole thing in a catch-all and punt.
+ (false-if-exception
+ (let lp ()
+ (clock-nanosleep clockid period-nsecs)
+ (system-async-mark interrupt target-thread)
+ (lp))))))))
(define (stop-preemption!)
(cancel-thread interrupt-thread))