reckfellENGINE

Semaphore

Permit counter for waking workers.

On this page
class SemaphoreReckfellSharpInherits RefCounted

A new Semaphore has zero permits. Post(n) adds n; Wait() and successful TryWait() consume one. Thus TryWait() is not a passive readiness query.

Store queue data separately. Before Dispose, coordinate worker shutdown: stop flag, Post to leave waiting, then join. Waiting on the main thread can stall the game. Thread-safe APIs. Counting, both Post overloads and wakeup were tested on Windows; FIFO, stress and threadless builds were not accepted.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors1

SemaphoreConstructor
# Semaphore
C#
public Semaphore();

Creates a counter with zero permits. Wait blocks without one; Post adds permits and Wait/TryWait consume one each. Not a data queue or an owner-tracking recursive mutex. Store data separately with coordinated protection; finish all waiting workers before Dispose.

Methods4

Post2 overloads
# Post · 1/2
C#
public void Post();

Adds a positive permit count; one when omitted. With no waiter, permits remain for future Wait/TryWait. Guarantees neither FIFO nor immediate execution of a particular thread. count<=0 emits native diagnostics; the method returns no Error. To stop a worker, wake it after updating a stop flag, then join; Post alone does not terminate arbitrary work.

# Post · 2/2
C#
public void Post(int count = 1);

Adds a positive permit count; one when omitted. With no waiter, permits remain for future Wait/TryWait. Guarantees neither FIFO nor immediate execution of a particular thread. count<=0 emits native diagnostics; the method returns no Error. To stop a worker, wake it after updating a stop flag, then join; Post alone does not terminate arbitrary work.

Parameters
NameTypeDefault
countint1
count

Positive permit increment, default 1; not a worker ID.

TryWaitbool
# TryWait
C#
public bool TryWait();

Nonblockingly consumes one available permit. True means the count decreased; false means no permit is available now. Not a side-effect-free readiness query. Successful TryWait requires neither a second Wait nor returning a permit unless your protocol explicitly does.

Returns bool

True after consuming one permit, or false without changing the count.

Waitvoid
# Wait
C#
public void Wait();

Blocks the caller until a permit is available and consumes one. Can wait indefinitely: this API has no timeout/cancellation. Do not use on the main thread without a guaranteed Post source; exclude dependencies on an already blocked thread. Wake and join every worker before disposing the Semaphore.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.