All Manuals > LispWorks User Guide and Reference Manual > 35 The MP Package

NextPrevUpTopContentsIndex

semaphore-acquire

Function
Summary

Acquires units from a semaphore.

Package

mp

Signature

semaphore-acquire sem &key timeout wait-reason count => flag

Arguments

sem

A semaphore.

timeout

A non-negative real.

wait-reason

A string or nil .

count

A non-negative fixnum.

Values

flag

A generalized boolean.

Description

The function semaphore-acquire acquires count units from the semaphore sem .

It attempts to atomically decrement the semaphore's unit count by count . If this gives a non negative result, then it changes the semaphore's unit count accordingly and returns true. The default value of count is 1.

However, if decrementing the semaphore's unit count would result in a negative number then semaphore-acquire waits until the semaphore's unit count is larger than count and tries again. If wait-reason is true, then it is used as the thread's wait-reason when waiting for the semaphore.

If timeout is nil , semaphore-acquire can wait forever. If timeout is true, it should be an integer. If the semaphore count cannot be decremented within timeout seconds, then semaphore-acquire returns false and the semaphore is unaffected. Pass timeout 0 if you do not want to wait at all.

Notes

You can get the current unit count of a semaphore by calling semaphore-count.

See also

make-semaphore
semaphore-count
semaphore-release
semaphore-wait-count


LispWorks User Guide and Reference Manual - 21 Dec 2011

NextPrevUpTopContentsIndex