main thread

The first thread a program starts with; in a browser page it also runs JavaScript and handles input, layout and painting.

In more detail

Other threads are usually started from it, and a long-running task on it blocks everything else it handles: in a browser, clicks wait and animations freeze. Keeping main-thread work short, yielding often and moving heavy work to worker threads keeps programs responsive.

Examples

Java: the main thread runs the main method.
In Node.js the main thread runs the event loop and every callback; heavy work belongs in worker threads or the libuv thread pool.
React time slicing breaks rendering into pieces that let the main thread handle input in between.

Related terms

Taught in

References