28 #include <gts/micro_scheduler/WorkerPool.h>
29 #include <gts/micro_scheduler/MicroScheduler.h>
33 namespace gts_examples {
66 addRef(3, gts::memory_order::relaxed);
81 addChildTaskWithoutRef(pLeftChild);
91 addChildTaskWithoutRef(pRightChild);
103 *sum = sumLeft + sumRight;
111 void blockingJoin(uint32_t fibN)
113 printf (
"================\n");
114 printf (
"blockingJoin\n");
115 printf (
"================\n");
122 result = microScheduler.
initialize(&workerPool);
127 auto start = std::chrono::high_resolution_clock::now();
137 auto end = std::chrono::high_resolution_clock::now();
139 std::cout <<
"Fib " << fibN <<
" is: " << fibVal << std::endl;
140 std::cout <<
"Time (ms): " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << std::endl;
A work-stealing task scheduler. The scheduler is executed by the WorkerPool it is initialized with.
Definition: MicroScheduler.h:81
void spawnTaskAndWait(Task *pTask, uint32_t priority=0)
Spawns the specified 'pTask' to be executed by the scheduler and then waits for its reference count t...
void spawnTask(Task *pTask, uint32_t priority=0)
Spawns the specified 'pTask' to be executed by the scheduler. Spawned tasks are executed in LIFO orde...
bool initialize(WorkerPool *pWorkerPool)
Initializes the MicroScheduler and attaches it to pWorkPool, where each worker in pWorkPool will exec...
void shutdown()
Stops the MicroScheduler and destroys all resources. The TaskSchuduler is now in an unusable state....
GTS_INLINE TTask * allocateTask(TArgs &&... args)
Allocates a new Task object of type TTask.
Definition: MicroScheduler.h:145
A Task payload that embeds TFunc and TArgs into the Task's data. It makes it easy to construct a Task...
Definition: Task.h:120
A collection of running Worker threads that a MicroScheduler can be run on.
Definition: WorkerPool.h:54
bool initialize(uint32_t threadCount=0)
#define GTS_ASSERT(expr)
Causes execution to break when expr is false.
Definition: Assert.h:144
The context associated with the task being executed.
Definition: MicroSchedulerTypes.h:54
MicroScheduler * pMicroScheduler
The MicroScheduler executing the Task.
Definition: MicroSchedulerTypes.h:59
Definition: 2_blocking_join.h:40