BluFedora Job System v1.0.0
This is a C++ job system library for use in game engines.
BluFedora Job System Library

This is a C++17 library for handling of Tasks / Jobs in a multi-threaded environment.

Examples

Minimal Example

#include <cassert>
#include <iostream>
static constexpr int k_DataSize = 100000;
static int s_ExampleData[k_DataSize] = {};
// Print the first 20 items for brevity
static void printFirst20Items()
{
for (int i = 0; i < 20; ++i)
{
std::printf("data[%i] = %i\n", i, s_ExampleData[i]);
}
}
int main()
{
Job::Initialize(Job::MemRequirementsForConfig({}));
// Initialize Dummy Data
for (int i = 0; i < k_DataSize; ++i)
{
s_ExampleData[i] = i;
}
std::printf("Before:\n");
printFirst20Items();
auto* t = Job::ParallelFor(
s_ExampleData,
k_DataSize,
Job::CountSplitter{6},
[](int* data, std::size_t data_size) {
for (std::size_t i = 0; i < data_size; ++i)
{
data[i] = data[i] * 5;
}
});
std::printf("After:\n");
printFirst20Items();
// Check that the jobs finished working on all items.
for (int i = 0; i < k_DataSize; ++i)
{
assert(s_ExampleData[i] == i * 5);
}
return 0;
}
API for a multi-threading job system.
void WaitOnTask(const Task *const task) noexcept
Waits until the specified task is done executing. This function will block but do work while being bl...
void Shutdown() noexcept
This will deallocate any memory used by the system and shutdown any threads created by 'bfJob::initia...
Definition: job_system.cpp:937
Task * ParallelFor(const std::size_t start, const std::size_t count, S &&splitter, F &&fn, Task *parent=nullptr)
Parallel for algorithm, splits the work up recursively splitting based on the splitter passed in.
Definition: job_api.hpp:607
void Initialize(const JobSystemMemoryRequirements &memory_requirements={}, void *const memory=nullptr) noexcept
Sets up the Job system and creates all the worker threads. The thread that calls 'Job::Initialize' is...
Definition: job_system.cpp:741
void TaskSubmit(Task *const self, const QueueType queue=QueueType::NORMAL) noexcept
Submits the task to the specified queue.

Architecture

Task

A Task is a single unit of work that can be scheduled by the Job System. Each Task has a total sizeof of 128bytes (2 * hardware interference size) with some of the bytes taken by essential bookkeeping date then the rest used for user storage.

A Tasks can be added as a child of another task, this means that when you wait on the parent Task then it will wait for all child Tasks as well.

Queues

A Queue hold a list of Tasks waiting to be executed. There are four different types of queues.

  • MAIN This queue has a guarantee that the task will be run on the main thread.
  • NORMAL Slightly lower priority than 'QueueType::HIGH'.
  • WORKER This queue has a guarantee that the task will never be run on the main thread.

Dependencies

  • C++ Standard Library (C++17 or above)
  • PCG Random