Class Sem

Package :
ipc

This class provides a semaphore facility. The implementation requires the accompanying C library uniipclib.so to be on the library path.

Instances of this class should not be created directly, but rather using the factory procedures open_public_sem, create_public_sem and create_private_sem

Source

Class summary
Methods defined in this class
attempt() get_id() get_value() remove() semop(n) semop_nowait(n) semop_poll(n, t) set_value(x) signal() wait()
Variables defined in this class
id

Method detail

attempt()

Attempt a wait, defined as semop_nowait(-1)
Source

get_id()

Return the underlying id of the semaphore.
Source

get_value()

Get the current semaphore value.
Source

remove()

Clean up the resources used by the semaphore. This should be called by the parent process after the semaphore is no longer needed.
Source

semop(n)

Perform a semop on the underlying sempahore. If n is >0 then n is added to the value. If it is <0 then the process is suspended until the value is >= abs(n), then abs(n) is subtracted. If n is zero, then the process suspends until the semaphore value is zero.
Source

semop_nowait(n)

Peform a semop with the IPC_NOWAIT flag set. This is the same as semop(), but instead of suspending the call will fail.

Source

semop_poll(n, t)

Repeatedly peform semop_nowait(), sleeping for a short period between each try until t milliseconds or semop_nowait() succeeds. Fails on a timeout; otherwise succeeds.

Parameters :
n - the parameter to semop_nowait
t - the timeout in milliseconds.
Source

set_value(x)

Set the value of the semaphore to x
Source

signal()

Perform the signal operation, defined as semop(1)
Source

wait()

Perform the wait operation, defined as semop(-1)
Source

Variable detail

id