Does multithreading require a new process?

Julia multithreading works by having Julia create N operating system threads at initialization, and then when you want to run something in parallel you @spawn a task… this task will get bound to a specific thread, and execute in parallel with other tasks on different threads.

it’s not clear to me how tasks get scheduled on a given thread and tasks can’t migrate from thread to thread yet.

I actually think you should set the JULIA_NUM_THREADS to be the same as your number of actual cores plus a small constant, like 2 or 3. Then you can have a few threads to do UI and file IO type stuff and the OS will take care of scheduling them, without tying up your computation threads.

once Julia can migrate tasks across threads this would be maybe less important.

2 Likes