On 9/4/2018 8:31 AM, Craig Allen wrote:
I saw that function, but was scared off by its documentation:

Like semaphore-wait, but semaphore-try-wait? never blocks execution. If sema’s internal counter is zero, semaphore-try-wait? returns #f immediately without decrementing the counter. If sema’s counter is positive, it is decremented and #t is returned.

I'm not sure why I'd want it to decrement the count, I really just want to see if my critical section is running. I will try it though, thanks.


'wait' takes the semaphore when it is available.  'try-wait' takes the semaphore if possible, or fails immediately if it can't.

AFAIK there is no way to simply 'check' if the semaphore is available.  In a multithread environment, such checking doesn't do much good anyway ... a positive counter value doesn't mean you actually can take a semaphore - some other thread(s) may beat you to it.

The canon [language independent] methods of "optimistic" locking are either to spin until 'try' returns true, or to combine one or a few initial probes using 'try' with a fall back to a normal wait if the probes fail.

George

--
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to