diff --git a/pkgs/racket-test-core/tests/racket/sync.rktl b/pkgs/racket-test-core/tests/racket/sync.rktl index 5341cdfc6d..36709e9513 100644 --- a/pkgs/racket-test-core/tests/racket/sync.rktl +++ b/pkgs/racket-test-core/tests/racket/sync.rktl @@ -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) diff --git a/racket/src/thread/sync.rkt b/racket/src/thread/sync.rkt index 7c5266a7a1..10383cc75d 100644 --- a/racket/src/thread/sync.rkt +++ b/racket/src/thread/sync.rkt @@ -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)])]