Panda3D
Public Member Functions | List of all members
Semaphore Class Reference

A classic semaphore synchronization primitive. More...

Public Member Functions

 __init__ (int initial_count)
 
 acquire ()
 Decrements the internal count. More...
 
int getCount ()
 Returns the current semaphore count. More...
 
 output (Ostream out)
 
int release ()
 Increments the semaphore's internal count. More...
 
bool tryAcquire ()
 If the semaphore can be acquired without blocking, does so and returns true. More...
 

Detailed Description

A classic semaphore synchronization primitive.

A semaphore manages an internal counter which is decremented by each acquire() call and incremented by each release() call. The counter can never go below zero; when acquire() finds that it is zero, it blocks, waiting until some other thread calls release().

Member Function Documentation

◆ __init__()

__init__ ( int  initial_count)

◆ acquire()

acquire ( )

Decrements the internal count.

If the count was already at zero, blocks until the count is nonzero, then decrements it.

◆ getCount()

int getCount ( )

Returns the current semaphore count.

Note that this call is not thread- safe (the count may change at any time).

◆ output()

output ( Ostream  out)

◆ release()

int release ( )

Increments the semaphore's internal count.

This may wake up another thread blocked on acquire().

Returns the count of the semaphore upon release.

◆ tryAcquire()

bool tryAcquire ( )

If the semaphore can be acquired without blocking, does so and returns true.

Otherwise, returns false.