cs & thread: repair for sync/timeout
If a `sync/timeout` on a semaphore (or simiilar asynchronous event) succeeds simultaneously with the timeout, the success could get lost.
This commit is contained in:
parent
11c6f1686c
commit
a20a27f5b0
|
@ -1528,6 +1528,22 @@
|
|||
(void (sync t))
|
||||
(test 'ok values v))
|
||||
|
||||
;; ----------------------------------------
|
||||
;; Try to make a semaphore-post succeed at exactly
|
||||
;; the same time that a `sync/timeout` times out
|
||||
|
||||
(for ([i 10])
|
||||
(define s (make-semaphore))
|
||||
(define t (thread
|
||||
(lambda ()
|
||||
(sleep (- 0.1 (* 0.001 (random))))
|
||||
(semaphore-post s))))
|
||||
(define r (sync/timeout 0.1 s))
|
||||
(unless r
|
||||
;; This will get stuck if the success of time sync got lost
|
||||
(sync s))
|
||||
(thread-wait t))
|
||||
|
||||
;; ----------------------------------------
|
||||
|
||||
(report-errs)
|
||||
|
|
|
@ -121,13 +121,13 @@
|
|||
timeout
|
||||
(timeout-at . <= . (current-inexact-milliseconds)))
|
||||
(start-atomic)
|
||||
(syncing-done! s none-syncer)
|
||||
(cond
|
||||
[(syncing-selected s)
|
||||
;; Selected after all:
|
||||
(end-atomic)
|
||||
(loop #f #f)]
|
||||
[else
|
||||
(syncing-done! s none-syncer)
|
||||
(end-atomic)
|
||||
;; Return result in a thunk:
|
||||
(lambda () #f)])]
|
||||
|
|
Loading…
Reference in New Issue
Block a user