reckfellENGINE

WorkerThreadPool

Ordinary and indexed shared-pool tasks with explicit collection.

On this page
class WorkerThreadPoolReckfellSharp

WorkerThreadPool uses the engine shared pool. AddTask invokes a Callable without arguments; AddGroupTask supplies an index to each invocation. Keep results/errors in owned data rather than the returned ID.

Completion status does not collect a job. One owner must call the corresponding Wait once, then stop using its ID. Waiting for unfinished work can stall a frame; poll across frames and exclude dependency cycles.

For a group use tasksNeeded=-1 or a positive number. Zero with nonempty elements can leave the current implementation unfinished; that branch was source-reviewed without executing a hang. A zero-element group completes immediately but still needs collection.

A worker has no ordinary access to the active EntityTree. Do not resize shared arrays during processing or confuse GetCallerTaskId() with group identity: group callbacks have individual task ID −1.

Complete batch-processing example, thread safety. Windows headless checks confirm lifecycle, indexed output and ID context; speedup, priority order, nested waits and invalid IDs were not accepted.

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

Properties1

SingletonProperty
# Singleton
C#
public static WorkerThreadPoolInstance Singleton { get; }

Borrowed wrapper of the engine shared pool; repeated access uses a cached wrapper. Do not Dispose/Free the Singleton or try to shut down the pool from a game job. Use static methods and collect only the task/group IDs you own.

Methods9

AddGroupTasklong
# AddGroupTask
C#
public static long AddGroupTask(Callable action, int elements, int tasksNeeded = -1, bool highPriority = false, string description = "");

Distributes elements Callable invocations, each with an index from 0 to elements−1. tasksNeeded controls worker-task count rather than element count or guaranteed concurrently active CPU cores; −1 selects from the pool. Do not pass 0 with elements>0: current code creates no workers and can leave the group unfinished; source-reviewed without executing a hang. elements=0 creates a completed empty group that still requires collection. Negative elements is invalid. Write results into preallocated independent slots; do not resize input/output while running. Index order is not promised. Confirm completion by status and call WaitForGroupTaskCompletion once.

Parameters
NameTypeDefault
actionCallable—
elementsint—
tasksNeededint-1
highPriorityboolfalse
descriptionstring""
action

Live Callable: no arguments for AddTask, an int index for AddGroupTask. Grants no automatic access to the active tree.

elements

Nonnegative element-invocation count; 0 invokes no action but still requires collecting the created group.

tasksNeeded

−1 for automatic selection or a reasonable positive worker-task count; not 0 for a nonempty group or an arbitrarily huge value.

highPriority

Pool queue preference, not OS realtime priority or an order/speed guarantee.

description

Diagnostic label, not a task identifier, filename or command.

Returns long

Group ID for status and one collection, or −1 for rejected elements.

AddTasklong
# AddTask
C#
public static long AddTask(Callable action, bool highPriority = false, string description = "");

Queues one no-argument Callable in the shared pool. Returns a task ID rather than the callback result; the pool exposes no callback return value. Publish your result through coordinated owned storage. Retain the Callable target and input through completion. After observing IsTaskCompleted, call WaitForTaskCompletion exactly once. Receiving an ID proves neither successful work nor a valid Callable; validate input yourself. highPriority guarantees no order/speedup. Implement application-level cancellation and error handling.

Parameters
NameTypeDefault
actionCallable—
highPriorityboolfalse
descriptionstring""
action

Live Callable: no arguments for AddTask, an int index for AddGroupTask. Grants no automatic access to the active tree.

highPriority

Pool queue preference, not OS realtime priority or an order/speed guarantee.

description

Diagnostic label, not a task identifier, filename or command.

Returns long

Task ID for status and one collection, not the callback result.

GetCallerGroupIdlong
# GetCallerGroupId
C#
public static long GetCallerGroupId();

Returns the group ID for the current group worker. Returns −1 on the main thread, outside the pool, or in an ordinary AddTask task. Not an element index: that index is supplied as a callback argument. All elements of a group report the same group ID.

Returns long

Current group ID or −1 outside a group callback.

GetCallerTaskIdlong
# GetCallerTaskId
C#
public static long GetCallerTaskId();

Returns the current ordinary pool task ID. Outside pool context it is −1. Group workers have no assigned public individual task ID and also return −1; use GetCallerGroupId for a group. Not an OS thread ID or main-thread ID. Do not collect a task from itself.

Returns long

Current ordinary task ID or −1, including inside a group worker.

GetGroupProcessedElementCountuint
# GetGroupProcessedElementCount
C#
public static uint GetGroupProcessedElementCount(long groupId);

Counts group element invocations that have returned, not assigned workers or started calls. Increments after the callback returns. Even count==elements does not replace IsGroupTaskCompleted and required WaitForGroupTaskCompletion. Query only before collection; an invalid/already collected ID emits diagnostics and returns 0, which does not prove an empty group.

Parameters
NameTypeDefault
groupIdlong—
groupId

An uncollected group ID owned by your code, not an element index or ordinary task ID.

Returns uint

Number of returned element callbacks; invalid IDs also yield 0 with diagnostics.

IsGroupTaskCompletedbool
# IsGroupTaskCompleted
C#
public static bool IsGroupTaskCompleted(long groupId);

Checks group completion without collecting it. True does not free the registry entry: one WaitForGroupTaskCompletion is still required. Poll across frames rather than busy-waiting the main thread. Stop using the ID after collection. False for an invalid ID comes with diagnostics and does not mean a running group.

Parameters
NameTypeDefault
groupIdlong—
groupId

An uncollected group ID owned by your code, not an element index or ordinary task ID.

Returns bool

True when completed, not proof of collection.

IsTaskCompletedbool
# IsTaskCompleted
C#
public static bool IsTaskCompleted(long taskId);

Checks whether an ordinary task callback returned. Extracts no user result and does not free the task. After true call WaitForTaskCompletion and check the Error. Stop using the ID after successful collection. Do not pass a group ID; invalid IDs yield false with native diagnostics.

Parameters
NameTypeDefault
taskIdlong—
taskId

An uncollected ordinary task ID owned by your code, not a group/thread ID.

Returns bool

True after callback return, not the user result.

WaitForGroupTaskCompletionvoid
# WaitForGroupTaskCompletion
C#
public static void WaitForGroupTaskCompletion(long groupId);

Waits for the group and collects its registry entry. Blocks the caller while work is unfinished; the main thread cannot process ordinary frames during that wait. Assign one collection owner, call once and discard the ID. Do not wait on a group from its own callback or while holding locks it needs: deadlock is possible. Returns no per-element results/errors; the application stores them. Provides no timeout/cancellation; invalid IDs are diagnosed.

Parameters
NameTypeDefault
groupIdlong—
groupId

An uncollected group ID owned by your code, not an element index or ordinary task ID.

WaitForTaskCompletionError
# WaitForTaskCompletion
C#
public static Error WaitForTaskCompletion(long taskId);

Waits for and collects an ordinary task, returning a wait Error rather than the callback result. After Ok stop using the ID. An unfinished task must not wait for itself; a pool worker attempting to await an unfinished task with an ID no newer than its own can receive Busy. Busy is not successful collection. Invalid IDs return InvalidParameter. Internal prevention of some deadlocks does not make arbitrary dependency cycles safe; hold no locks needed by workers and do not await main-thread actions from a blocked main thread. Invalid nested waits were source-reviewed only.

Parameters
NameTypeDefault
taskIdlong—
taskId

An uncollected ordinary task ID owned by your code, not a group/thread ID.

Returns Error

Ok after collection, InvalidParameter for an invalid ID, or Busy for a prohibited nested wait.

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.