[plt-scheme] semaphore-like event

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Mon Jul 20 19:43:07 EDT 2009

On Jul 20, 2009, at 7:13 PM, Matthew Flatt wrote:

> 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:

Aha! That's that I was looking for, thanks!

Ryan



>
>
>> (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.