skip to content

In a game engine, what do the main (game) thread, the render thread and the audio thread each own, and why are they kept separate?

level: juniorimportance: should knowfreq 55%

answer

  1. who owns the game state
  2. a copy the renderer reads
  3. the audio device's fixed clock
  4. a hitch you see versus hear

basics

~20 s

The main thread runs input, gameplay and simulation and owns the game state; the render thread turns a copy of that state into graphics-driver work; the audio thread mixes sound against the device's hard deadline, so a slow frame never starves it.

solid answer

~50 s

The **main (game) thread** polls input, runs gameplay and simulation, and is the single writer of the authoritative game state; in a job-based engine it also launches the frame's jobs. The **render thread** works from a copy of what the renderer needs (transforms, which objects exist, material parameters, camera) and does the CPU side of rendering: preparing draws and handing them to the graphics driver, so driver cost stays off the game thread. The **audio thread** mixes voices into the buffer the audio device plays, which must be refilled on a fixed clock every few milliseconds. A visual hitch costs one late frame; a missed audio block is an audible click, so mixing never waits on gameplay. Many engines add I/O threads and a pool of worker threads that run jobs for all of them.

go deeper

for a junior

Name the three threads and what each owns: the main thread runs input, gameplay and state; the render thread prepares and submits drawing; the audio thread mixes sound against the device clock.

for a middle

Explain how data crosses between them: a render copy swapped at a sync point and a non-blocking audio command queue, so no thread reaches into another's data.

for a senior

Show the consequences: the render thread's extra frame of latency, why audio code avoids locks and allocation, and what breaks when gameplay writes render-side data.

for a principal

Weigh a dedicated render thread against running render work purely as jobs, and decide which thread owns which state so ownership stays simple as the team grows.

## Why an engine splits work across threads A game does several kinds of work every frame, and they do not share one deadline. Gameplay and simulation must finish before the frame can be drawn; the CPU side of rendering must hand the graphics driver a complete frame; the audio device must receive fresh samples on a fixed schedule whether or not the frame is late. Putting all of that on one thread means every piece waits for every other piece, and the slowest sets the pace for all. Engines therefore give the long-lived, deadline-bound **roles** their own threads, and run the bulk of the parallel work as **jobs** on a pool of worker threads. ## The main (game) thread The **main thread**, often called the **game thread**, is the heart of the frame: - it pumps operating-system messages and polls input devices; some operating systems require window and input events to be handled on the process's first thread; - it runs gameplay logic, scripts and the simulation step; - it is the **single writer** of the authoritative game state, which keeps gameplay code free of data races; - in a job-based engine it builds and launches the frame's jobs, and it usually runs jobs itself while it waits for them. ## The render thread The **render thread** does the CPU side of rendering. It does not draw pixels; the GPU does that. Its work is: - reading a **copy of render-relevant state** (world transforms, which objects exist, material parameters, camera and lights) that the main thread handed over at a sync point; - preparing draws: deciding what to draw, sorting it and building per-object constant data; - talking to the graphics driver, whose calls can be expensive and, in some older graphics interfaces, are tied to one thread at a time. Because the render thread works from its own copy, it can prepare frame N while the main thread simulates frame N+1. The two overlap, and frame time drops towards the slower of the two instead of their sum. The price is about one extra frame of latency and a rule that gameplay code never writes render-side data directly. ## The audio thread The **audio thread** mixes every playing voice (volume, pitch, spatialisation and effects) into the buffer the audio device plays. The device asks for that buffer on a fixed clock. In an illustrative setup with 512-sample blocks at 48 kHz, a new block is due every 512 / 48,000 s, about 10.7 ms. Missing that deadline produces an audible click or dropout. A single late visual frame often goes unnoticed; an audio glitch is almost always heard. So mixing never waits for gameplay: 1. the main thread sends play, stop and parameter commands through a non-blocking queue; 2. the audio thread applies them at the start of its next block; 3. the mixing code avoids locks and general-purpose allocation, either of which could stall it behind a lower-priority thread. ## Other threads you will meet - **Worker threads**, usually about one per core, that run jobs for everyone: culling, particle updates, draw preparation, physics work. - **I/O and streaming threads** that wait on file reads and decompression so that no frame-critical thread has to. - **Network threads** on online games. A dedicated server has no render or audio thread at all: its main thread runs the fixed simulation tick and hands wide work to workers. ## Summary | Thread | Owns | Deadline | Talks to others through | |---|---|---|---| | Main (game) | Input, gameplay, simulation, authoritative state | The frame | Launches jobs; hands off a render copy; posts audio commands | | Render | A copy of render state, draw preparation, driver calls | The frame, one behind | Swaps the copy at a sync point | | Audio | Voice mixing into the device buffer | Every audio block, hard | Reads a non-blocking command queue | | Workers | Nothing long-lived; they run jobs | Set by whoever waits on the job | Job queues and dependency counters | The design principle is the same everywhere: each piece of shared state has **one owner**, and other threads receive copies or messages instead of reaching into it.

  • Why must audio mixing code avoid locks and general-purpose memory allocation?
    It runs against a hard deadline. If it blocks on a lock held by a lower-priority thread, or a general allocator stalls, the next block is not ready and the device plays a glitch. Audio threads therefore take commands from a non-blocking queue and mix into preallocated memory.
  • Does a dedicated render thread still make sense in an engine that already has a job system?
    Often yes: it gives the renderer its own frame to work in, overlapping with the next simulation frame, and it can launch jobs for culling and draw preparation. Some engines drop the dedicated thread and run render work purely as jobs; the overlap then comes from the job graph and double-buffered state instead of a thread.

  • The render thread draws the pixels itself, so it replaces the GPU's work.
  • Audio can be mixed at the end of the game frame because a late block goes unheard.
  • Gameplay code may modify render-side objects directly whenever it is convenient.
  • One thread per subsystem is the goal; more dedicated threads always means more speed.
  • A separate render thread makes frames faster with no cost in latency.