What is the best way to say "wait until 'current-user-set?' returns true"? I've been through the Events chapter in the Reference and nothing seems like a great fit. I could do polling via sleep or alarm-evt but that seems inefficient. Is there a better way?
Jay McCarthy
unread,
Mar 19, 2021, 12:02:20 PM3/19/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to David Storrs, Racket Users
The best thing is to use a semaphore instead of a mutable reference.
If you can't do that, then I think that you should combine the mutable
reference with a signaling semaphore. If you can't do that, then I
can't think of anything but a poll.
The best thing is to use a semaphore instead of a mutable reference.
If you can't do that, then I think that you should combine the mutable
reference with a signaling semaphore. If you can't do that, then I
can't think of anything but a poll.
Is this the kind of thing you meant by 'signalling semaphore'?
#lang racket
(define x #f) (define sema (make-semaphore 0))
(define (wait-on-x) (sync (semaphore-peek-evt sema)) always-evt) (define (set-x! val) (void (thread ; don't print the thread object when running in the repl (thunk (sleep 3) (set! x val) (semaphore-post sema)))))