top of page
Search
Writer's pictureSadanand Naik

Job System for Multi-Threading

Updated: Dec 17, 2019

In accordance with improving the performance of the engine, a job system using a pool of threads from the boost library has been created to provide parallel processing across multiple subsystems of the engine. This system works hand in hand with the Event system to parallelize most of the major tasks in the game engine such as rendering, physics calculations, scene updates, etc..


Current Structure:


  1. Singleton class.

  2. Creates a set number of threads based on the system’s hardware concurrency and pushes them into a vector.

  3. Each thread constantly runs a while loop where it checks the worker queue for any jobs and executes them if it finds any.

  4. The data in the work queue is protected via mutex locks during push and pop.

  5. Takes in any type of function pointer with any number of input arguments through Variadic Templating. Once the arguments are expanded they are pushed into an anonymous function. This lambda is pushed to the work queue.

Work Queue.


Templated Submit Function.




Possible Future improvements:

  1. Switching to boost’s lockless queue for lockless multi-threading.

  2. Adding task-waiting feature for threads to be able to wait for other threads to finish processing data that they require for their own task.


Interface:

The thread’s singleton reference needs to be called via the private constructor through a getter function. Once the reference is available, any type of function can be passed into the job system via the submit() function. Member functions require std::bind() for their implicit argument(the object pointer) or lambda implementations in order to be able to be passed into the job queue.

6 views0 comments

Recent Posts

See All

Comments


bottom of page