Job System - Pyrohax/Simpleton GitHub Wiki

Goal

The final goal of the job system is to create a safe asynchronized task executer that effectively utilizes all cores in the CPU.

Current state

Right now, however, it is simply a way to parallelize large functions by passing them to the subsystem. It is currently NOT protected against data racing, and should currently ONLY be used for when you're certain you won't be changing the same memory with multiple threads.

Usage

Lets assume we want to do two heavy load operations that take 8ms each. We could approach this issue by simply adding two jobs as such, after which we can return safely:

bool LoadWorldModel()
{
    myWorldModel = Load("../world.gltf");
    return true;
}
bool LoadGiantCastleModel()
{
    myGiantCastle = Load("../world.gltf");
    return true;
}

bool SubSystem::Init()
{
    JobSystem& jobSystem = GetJobSystem();
    jobSystem.AddJob(&this->LoadWorldModel);
    jobSystem.AddJob(&this->LoadGiantCastleModel);
    return true;
}

After the frame in which this function was called ends, we are guaranteed to have finished function LoadWorldModel and LoadGiantCastleModel. Passing in jobs that take longer than three seconds to complete will print a warning in the log.