Package coro :: Module _coro :: Class inverted_semaphore
[hide private]
[frames] | no frames]

Class inverted_semaphore

object --+
         |
        inverted_semaphore

Inverted semaphore.

An inverted semaphore works very much like a regular semaphore, except threads block _until_ the value reaches zero. For example, if you want a thread to wait for 1 or more events to finish, you can have each event raise the value (always nonblocking) and have your waiter thread call block_till_zero.

The constructor takes one optional parameter, the value to start the semaphore with. It defaults to 0.

Instance Methods [hide private]
 
__init__(...)
x.__init__(...) initializes x; see help(type(x)) for signature
 
__int__(x)
int(x)
 
__long__(x)
long(x)
a new object with type S, a subtype of T
__new__(T, S, ...)
 
acquire(...)
Acquire a number of resource elements.
 
block_till_zero(...)
Block until the inverted semaphore reaches zero.
 
release(...)
Release a number of resource elements.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables [hide private]
  _waiting
: A fifo of coroutine objects waiting for the semaphore to reach zero.
  value
: The value of the inverted semaphore.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(...)
(Constructor)

 
x.__init__(...) initializes x; see help(type(x)) for signature
Overrides: object.__init__

__new__(T, S, ...)

 
Returns: a new object with type S, a subtype of T
Overrides: object.__new__

acquire(...)

 

Acquire a number of resource elements.

This never blocks.

Parameters:
  • value - : The number of resource elements to acquire (add to the semaphore). Defaults to 1.

block_till_zero(...)

 

Block until the inverted semaphore reaches zero.

This will return immediately if the value is already zero.

release(...)

 

Release a number of resource elements.

This never blocks. This may wake up waiting threads.

Parameters:
  • value - : The number of resource elements to release (subtract from the semaphore). Defaults to 1.

Instance Variable Details [hide private]

_waiting

: A fifo of coroutine objects waiting for the semaphore to reach zero. (C only).

value

: The value of the inverted semaphore. Also available via __int__.