class
Scheduler
Allows the caller to post tasks which will then be executed on one of the threads managed by the scheduler.
The scheduler can create internal worker threads to process tasks, or you can bind existing threads (created externally).
External threads need to be bound/unbound to the scheduler via BindToCurrentThread/UnbindFromCurrentThread, and you need to call ProcessTasksOnCurrentThread() regularly for them to actually process queued tasks.
All executing tasks are allowed to yield mid-execution, at which point a new task will start executing on the thread. The suspended task can be resumed from the point it yielded as the scheduler will preserve its context in a fiber.
Public
Constructors
Scheduler
Methods
~Scheduler
GetInformation
Returns information describing the scheduler.
BindToCurrentThread
Binds the scheduler to the current thread, allowing it to process tasks.
The thread is managed externally - you must call UnbindFromCurrentThread() before the thread exits. Can be called from multiple threads to bind them all to the scheduler.
Returns: Worker ID assigned to this thread, or ~0u if binding failed (max threads reached or already bound).
ProcessTasksOnCurrentThread
Processes all pending tasks on the current bound thread and returns.
Must be called from a thread that has called BindToCurrentThread(). Typically called in a loop from your own thread (e.g., game loop).
staticUnbindFromCurrentThread
Unbinds the scheduler currently bound on the calling thread.
This will wait until all operations complete before returning.
Post
Queues a new task for execution by the scheduler.
The task will be executed on one of the worker threads (either internal or external).
Private
Methods
TryStealWork
Attempts to steal work from another scheduler thread.
- thief
- Thread trying to steal the task.
- random
- Random value based on which to pick the worker to try to steal from.
- outTask
- Stolen task, if successful.
Returns: True if a task was stolen, false otherwise.
NotifyOnBeginSpinning
Notifies the scheduler that a scheduler thread has begun spinning.
This allows the scheduler to prioritize work on this worker.