thread

A path of execution inside a process that the operating system schedules on a processor; one process can have many.

In more detail

Threads of the same process share its memory, which makes communication fast and data races possible. Creating many threads is expensive, so runtimes often multiplex many lightweight tasks onto a few threads.

Examples

In the browser: A browser tab uses a main thread for JavaScript, styles and layout, plus other threads for compositing, parsing and networking. Web Workers let your own code run on an extra thread so heavy work does not freeze the page.
Go: the Go runtime runs many goroutines on a few threads
Java: new Thread(() -> System.out.println("work")).start(); calling run() instead of start() runs on the current thread.
Thread worker = new Thread(() -> System.out.println("work")); worker.start();
The kernel schedules threads, not whole processes, so a busy process with many threads can use several processors at once. Threads in one process share memory and open files, which makes communication cheap but mistakes contagious.
Node.js runs your JavaScript on one main thread and uses extra threads for libuv's thread pool, garbage collection and worker threads.

Related terms

Taught in

References

Certification courses