Job System Implemention in C++ for university course "Advanced Game Development"
Other comments and explanations are in source code.
Performance Comparison:
As we see the fastest possible runtime is already achieved with 3 threads (Reason for this is explained in main.cpp
).
Start in parallel:
-p
Otherwise starts in serial mode
Start with different amount of threads:
-t [numThreads]
Otherwise starts with a std::hardware_concurrency() - 1.
#define HTL_USING_LOCKLESS // using lockless variant of worker queue
#define HTL_EXTRA_LOCKS // still using locks in lockless queue for testing
#define HTL_TEST_DEPENDENCIES // test if correct dependencies are met
#define HTL_WAIT_FOR_AVAILABLE_JOBS // if set, conditional var wakes on executable jobs instead of size > 0
#define HTL_TEST_ONLY_ONE_FRAME // main loop returns after one execution
#define HTL_EXTRA_DEBUG // additional debug output
#define HTL_SORT_JOBS // sort jobs to be allow workers to instantly start after pushing
THEY TERK ERR JERBS!
.*/#%%%%%#####/**
.#%%%#%%%%#&####%%%#%%%%%%%%%%*
.%%%%###%%%%##############%#####%%%%%
%%%#################%########%######%%#%,
*#%%%%%%%%%%%%%######%%#%####%#######%########%#%%
/%%%%%%%%&%%%*.....%%###%%%%%%%%%#%######%############%#
/#%%%%%%%%%%,.........%%%#%%%%%%%%%%#%#%%##%##########%##%%
%#%##%##%%(.............#%#%%%*#%%%%%%%%%%%%#%####%%###%###%%
%######%%/.................%%%%.*%%%%%%%%%%%%%%%###%%%%#%#%%#%#
%%#%##%#%..................../%%%.,%%%%%%%%%%%%%%####%%%%%#%%#%%(
,%##%#%%#......................./%*..(%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%#%#%%........((((((####(*...........#%%%%%%%%%%%%%&%%%%%%%%%&%%,
.%%%%%&%.....................(####.....,(((%%%%%%./%%%%%%%(%%%%%%%%#
.%%%%#&/.....................................,#%%%%...*#%%%#.%%%%%%#
%%%%%&.............. ... ............#%%#%(
%%%%%........... . ...........%%%%.
#%%.........., #* / . *........%%%#...
...*#%.......... . . .........%%.,...
..,..,,......... .,. ................
,....,,......... .. ... .........,....*.
..*..,,.........,. ..,...*...... * ..*..........* ...
.. *,......................................................,..
..*.,,...................(............................,,..
%........................,/(..#......................,.,%
%%%%%,,,...........,%%%%%%%%%%%%%%%%%%%*.........,.,%%%%%
%%%%%%%..,.......,%#%%%%%%%%%%%%#%%%%%%%%,........#%%%%%#
##%%%%%%%..,.. .(%%%%%#%%#%##%##((%%%%%%%%#...,,.#%%%%%#(
.#%%%%%%%%,.,,%%%%%%%/,,,.....,.,.,*%%%%%%%#..%%%%%%%#
,#%%%%%%%%((*%%%#,.,,,,,,,,,,,,,.,,,,,*(%%##%%%%%%%#
,%(%%%%%%%%,,,,,,,,,,,,,,,,,,,.,,.,.,,&&&&&&&%#%.
../(##&%%%%&&&&%&&%%(..,...,,..........%%%%&&%#%&&&&%%&&&%.
#&&%%#%%%&&&&%%%&&&&##&&&%&&#................&&&&&&&%%#%%&&&%%&&&%%%#
#%%%&&&&&&&&&%&%#%&&&&&%%%%&&&&&&&&.............../&&%#&&&%%%%%%&&%&#%&&&###%&
*//%%&&&&%%#%&&&&&&%%%&&&&%%%%%%%%%&&&%&&&&( ... #&&&&&&&&&%%%%#%%%&&&%%&&&&&&&&&*
%&&%&&%&%%&&%##(%#%&&&&&&&&&%%%%#%%%%%%&&%%&&&&&&&&* %#%%%&&&%%%&%%%%#%%%&&&&&&&&&&&%%%%%
#%##&&%&%#%....,**.,*,,*.,......(%%%#&&&&%%&%&&#%%%%%( #%%%#%%&&&%%%&&&%%%%%&&&&&&&&&&&%#%&&&&&.
#&&&@&&&&&&#..*.../*.,...,............./&%#&&&&#%%%%&%%* &&&%&&&&&&&&&&&&&&&&&&&&&&&&&&%%&&&&&&&&&&%/
&&&&&&&&&&&%.........,....................&&&&&&&&%&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&%%#%%&&&&&&&&&%%%%%#%/
*%#%&&%&%%%% ............................(..&&&%&&&&&&&&&&&&&&&&&%&&&&&&&&&&&&&&&&&&%(&&&&&&&%%%&&&%%&&&%%,
%%%&&%&%%%% ..............%*..@&&&&&&&&&&&&&&&&&&&&&&&&%&&&&%%&%%%&%%, #&&&#%&&&&&&&&&&&%%%%*
...............%&/ %%%%#%%%%%##%%%%##%%&&&%%%&&&%%%%%%%%%, /%%%%&&&&&&&&&&%%%
%*....*(%&/....%&&%%%%%%%%%%%%%%&%%%%&&&&&%&&&&&&&&&&&&&, ..,#&&%&&&%%&&%%
%%&&&&&&&@@@.../&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&, ,....,.....,#%%#%
*&&&&&&&&&&&*...&&&&&&&&&&&&&&&&&&&&&%&&&&&&&&&&&&&&&&&& .............
&&&&&&&&&&&@..&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&%%%&&% .....,,*.,,.,*.
(&&&&%&%&&&&&%&&&&%%%##%%%%%#%%%%%#%%&&&&%#&&&&%%#%#%%# ......,.,,*.,,
,#############################################################################################
/################################################(############################################
/########(########################%##########(#########################%######################
/#%#%###%###%%%%%%##%%#%##%##%##%%##%##%%%###%##%#%%#%%#%%#%%%#%#%%##%##%%#%%%###%##%#%%#%%#%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%(
(%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%################################################################################%%%%%#
/%%%%############(#######################%###########################################%%%%%
%%%%################################################################################%%%%%
(%%%###############%&%%&&%%%%&&%%%%%%%%%%&%%%%%%&%&%%%%%%%%&%%&%%%%&&%##############%%%%.
%%%###############%#############(###################################%##############%%%%
#%%###############&####%############################################&##############%%%/
%%############%##%##########################%#####################%%##############%%%
###############%################################################%&##############*
JOBS DONE!
.,,...,,.
./(**//(//////////*** .*******.
(#(//,/(((/((((((((#(((//**/*//(((##(
%%%%#(/*/((((((#####%%%%%%###(/*//(((##%%##
#&%, ,#%%%%%#(**(((((###%%%%#//(#%%%####**/(%%%%%&%%%%/
&&%%%%, %%%%##(///(####%%%/. .*(#%#(((((((#%%&%%&&&%%%
%%%%%%%%%%/ #%%%%#((//((#%%%%( */(//. .,*(%%%#((%%&#*,....,(##
#%%%%%%%%%%%%## &%%%%##((((#%%%%%%. *(/%%*#. ,*#(%#(/*,,,, .((((* .#%
.%%%%%%%%%%%%%%%%%#, *&%%######(((##%%%%%/ ,/#(*. .*((((/,,,,((((((/&#(,*%
%%%%%%%%%%%%%%%%%%%%%%(#%###(((/**,,,,,*,,,,*/(##%*,,***%#(#/**(%%&%%%##.**,,(#&
##################%%%&&&%##((//*,,......,,,,,,,,**,,,,,*//#/(%&&&&&&%%##%%%%%%###.
/####################%&&&%#(//******,,***,*****//((((#%%%&&%###((((((((((#%##((/////*
,####################%&&&%#((///******/////(((###%%%%&%#(/*****/***,,,.,,,,,%&&&%%%#((((.
##########%%%%%%%%%%%&&%%%(((((((((((###%%%%%%%%&%#((///*******,,,,,,,,,,,,,,,(&&&&%####
,#######%%%%%%%%%%%&&%#((&#########%%%%%%%%%&&%##(////*******,,,,,,,,,,,,,,,,,,/(%&&&&%
,#####%%%%%##########%%%##%#%%%%%%%%%%%%%%#((((/((/*******,,,,,,,,,,,,********(#&&&&
###%%%%%######%%%%%&%%%%%%%%%&%%#((//////(///////******,,,,,***************(#&&/ *.
##%%%%%%%%%%%%%%%&&%%%%%&%(/##(((//////**/***********************/*******/(#% ,,,
#%%%%%%%%%%%%%&&&&&%((#**/*,*/(/**,,.*******///**************////******//#%%%( ,...
(%%%&%#.. *&%##(*/(@%&@&***,,. ,*************///****************/////##((#%# .. .
#%(//(%@&****,,.. ,******#(/****(***********************//((((%. #/(/, *. .
#///(@&/**,,,.. .**,,,,,,.(,,,#/,,,,,,,,,,,,,,,,,,,,,,,,,**#/(*,,,,,,,,,, .
/(//%@%,,,,,.. ,*,. . #,,,*.,,,,,,,,,,,,,,,,,,,,,,,,,**. * .
%/(&@*,,,,,... ...,///*,,. %&@* ,@@&%#/*,,,,,/&. ,,,*.%@@@@@..* ..,
,%(@@/**,,,......,,,,***,,..* #@( *&@@@@@@@@%../#..,(((*(.@@@@.,,..... .....,,,
%#%@/,,,,,,,,,,,,,,,,,,.../&/ .%#/*****,,,,,,,,,,,,***//////////(((/..........,,,
%(@(**,,***,,,,,,,,......&@@/(*,,,*********////(((((#(((#(#########((*..,,,
#%(@@&&#(/,,...,,,......&%/,..,,**//(((((((((####(((##########%##%%##%%&
&%((%&@@@@@@@@@@@@@&&&%/*,,***////((##((#########(((((((#((((##%%%%%%#.
&%#(((((#%&&@&&&&&%%#/***/*/////((((((((((((((//*********///(######%#(%%
#%#((((/(//((((((/**,,**/////(((((((((///////***,,,,,,******/(((#####%
#((((//////*********////((///////////********,,***********/((####%%
(#####(((/***///////////////////***************/////(////(((##%%.
.#%##**///(/////////////**//***********//////((((#((((((((###%
/#%##(((/////////////*////////////////(((((####((((((#####/
#((((///////*////////////////(((((((((######((#####%&%/
#((((/////*/////////////((((((((######((#####%&%/