You can start a second thread that monitors the condition as well as a
timer; if the timer goes off first, then you kill the first thread; if
the condition happens first, then it continues. If you don't want the
second thread to have to monitor the condition, then the first thread
should tell the second thread that everything is okay, such as by
setting a semaphore.
Like this:
```
#lang racket/base
(define (kill-unless-sema-after-secs t sema secs)
(thread
(λ ()
(sync sema
(handle-evt (alarm-evt (+ (current-inexact-milliseconds)
(* 1000 secs)))
(λ _
(kill-thread t)))))))
(module+ main
(define t
(thread
(thunk
(let loop ()
(define sema (make-semaphore))
(kill-unless-sema-after-secs t sema secs)
(define-values (len shost sport)
(udp-receive! socket buffer))
(semaphore-post sema)
;; xxx do stuff
(loop))))))
```
--
Jay McCarthy
Associate Professor @ CS @ UMass Lowell
http://jeapostrophe.github.io
Vincit qui se vincit.
> --
> 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
racket-users...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/CAE8gKocoTTN0VfOToioMq3xK_0ysqAQVHmZ%2BmiFS9iutzY0sxQ%40mail.gmail.com.