Ah. Thanks. On Fri, Mar 19, 2021 at 1:33 PM Jay McCarthy <[email protected]> wrote:
> It is not a built-in thing. I am talking about the use-pattern of a > condition variable: > https://en.wikipedia.org/wiki/Monitor_(synchronization)#Condition_variables > > -- > Jay McCarthy > Associate Professor @ CS @ UMass Lowell > http://jeapostrophe.github.io > Vincit qui se vincit. > > On Fri, Mar 19, 2021 at 1:02 PM David Storrs <[email protected]> > wrote: > > > > > > > > On Fri, Mar 19, 2021 at 12:02 PM Jay McCarthy <[email protected]> > wrote: > >> > >> 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))))) > > > > (define (check-x) > > (match (sync/timeout 10 (wait-on-x)) > > [#f (displayln "timeout")] > > [_ (displayln "success")])) > > > > (set-x! 7) > > (check-x) ; pauses for 3 seconds, then outputs "success" > > (check-x) ; outputs "success" immediately > > (check-x) ; ibid > >> > >> > >> -- > >> Jay McCarthy > >> Associate Professor @ CS @ UMass Lowell > >> http://jeapostrophe.github.io > >> Vincit qui se vincit. > >> > >> On Fri, Mar 19, 2021 at 11:59 AM David Storrs <[email protected]> > wrote: > >> > > >> > Suppose I have a function that tests for some condition, e.g. > >> > > >> > (define current-user (make-parameter #f)) > >> > (define (current-user-set?) (not (false? (current-user))) > >> > > >> > 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? > >> > > >> > -- > >> > You received this message because you are subscribed to the Google > Groups "Racket Users" group. > >> > To unsubscribe from this group and stop receiving emails from it, > send an email to [email protected]. > >> > To view this discussion on the web visit > https://groups.google.com/d/msgid/racket-users/CAE8gKocbPgjcFAF_o2g6mhZBEH8PpeGyJ4CwznKc3DZkMjY%3DGw%40mail.gmail.com > . > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAE8gKofsHVJfBZCX12Sm%3DeNSeEj4AmehPYhsS2wJf8G3q%3DRXXA%40mail.gmail.com.

