[plt-scheme] semaphore-like event

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Jul 20 19:13:42 EDT 2009

At Mon, 20 Jul 2009 18:45:09 -0400, Ryan Culpepper wrote:
> I'm trying to make an event that is initially not ready, but once a  
> 'release' operation is performed, it is ready forever afterwards. In  
> particular, it becomes ready in synchronizations that have already  
> started and are currently blocked. (Imagine if semaphores supported an  
> operation that bumped the semaphore's internal counter to +inf.0. That  
> would do it.)
> 
> My question: Is there a way to do this without creating an extra thread?

I think you're looking for `semaphore-peek-evt'. That gives you
something like incrementing a semaphore to +inf.0:

 > (define s (make-semaphore))
 > (define sp (semaphore-peek-evt s))
 > (sync/timeout 0 sp)
 #f
 > (semaphore-post s)
 > (sync/timeout 0 sp)
 #<semaphore-peek>
 > (sync/timeout 0 sp)
 #<semaphore-peek>
 > (sync/timeout 0 sp)
 #<semaphore-peek>



Posted on the users mailing list.