Game dev
Saved & recent

Multithreading

Related terms: main thread, render thread, job system, worker thread, race condition

A CPU has several cores. A game that uses only one wastes most of the machine. Engines split the work: a main thread runs game logic, a render thread prepares draw calls, and a job system chops big tasks such as physics, animation and culling into small jobs spread over worker threads.

The hard part is shared data. Two threads touching the same data at once cause a race condition: a bug that appears rarely and vanishes when you look for it. That is why most gameplay code stays on the main thread.

Further reading
Unity: Job system overview
main worker 1 worker 2 worker 3 render 0 4 8 12 16 game update finalize physics animation visibility previous frame submit dispatch join frame time (ms)
At 5 ms the main thread dispatches physics, animation and visibility jobs. After they complete, the main thread joins them and hands the frame to the render thread.

View in the full Game dev collection