Multithreading

Nicolas Jacquin

Multithreading allows a program to run multiple computations at the same time on separate CPU cores. This is especially useful for CPU-bound tasks where raw computing power is the bottleneck.

In Julia, multithreading is enabled with the environment variable JULIA_NUM_THREADS, and used via macros like Threads.@threads and Threads.@spawn.

The goal is to split work into smaller, independent parts that can be safely computed in parallel.

We’ll also talk about asynchronous programming, which defines coroutines running at the same time on a single thread, and able to yield control to each other while they wait for something.

Downloadable content

Notebook: julia | pdf | html