|
CX Framework
Cross-platform C utility framework
|
Modules | |
| Task Objects | |
| System Task Queue | |
| Task Queue Configuration | |
| Task Queue Lifecycle | |
| Task Operations | |
| Task State Queries | |
| Task Queue Types | |
| Task Requirements | |
| Task Resources | |
The CX task queue system provides an object-oriented framework for managing asynchronous task execution in multithreaded applications. It supports everything from simple fire-and-forget tasks to complex dependency graphs with resource management.
The task queue system is built on several layers:
BasicTask - Bare minimum task with no dependencies or scheduling. Just a run method and state tracking. Suitable for simple operations that need to run on a worker thread.
Task - Extends BasicTask with a name, timing information, and completion callbacks. Can wait for completion with timeouts.
ComplexTask - Extends Task with support for:
MultiphaseTask (MPTask) - Extends ComplexTask for multi-phase operations with an internal state machine. Phases can be added as an array of functions that execute sequentially, with optional fail phases for error handling.
Task queues can be configured in various modes using preset functions:
Single Thread (tqPresetSingle) - One worker thread for UI or single-threaded work:
Minimal (tqPresetMinimal) - Lightweight threading for background work:
Balanced (tqPresetBalanced) - General-purpose configuration:
Heavy (tqPresetHeavy) - High-performance under sustained load:
Manual (tqPresetManual) - No worker threads, call tqTick() manually:
TQ_ManagerThread - Use a dedicated thread for queue maintenance instead of stealing idle worker time. Recommended for heavy workloads.
TQ_Monitor - Enable queue monitoring for debugging stuck tasks. Reports tasks that are running too long, waiting too long, or stalled without progress.
TQ_NoComplex - Restrict queue to BasicTask/Task only, disabling ComplexTask features. Reduces overhead when dependencies and scheduling aren't needed.
TQ_Manual - No thread pool; queue must be ticked manually with tqTick().
TQ_Oneshot - In manual mode, only run one task per tick instead of all available tasks.
ComplexTask can require resources before execution:
TRMutex - Mutex-based serialization. Simple and efficient for moderate contention. Tasks are woken in approximate FIFO order.
TRFifo - Strictly ordered FIFO queue. Guarantees serialized execution in registration order. Scales efficiently to large numbers of waiting tasks.
TRLifo - LIFO (stack) ordering for specialized use cases where most recent requesters should be serviced first.
TRGate - One-time event gate. Multiple tasks can wait on a gate that opens once, releasing all waiting tasks. Can be sealed to fail tasks that depend on it.
ComplexTask supports several types of dependencies:
Dependencies can have timeouts:
ComplexTask can be scheduled to run at future times:
Tasks can also reschedule themselves by returning TASK_Result_Schedule or TASK_Result_Defer from their run method, with the delay specified in the TaskControl structure.
Enable monitoring with tqEnableMonitor() to debug task queue issues: