Maximum number of Threads

Is the max number of threads that can be spawned limited by the number of cores of my CPU?
For example by using std.Thread.getCpuCount()?

No maximum number of threads is limited by your OS

1 Like

No. Generally speaking, there is not, but depends on the operating system. A given OS may limit the number of threads to some multiple of cores (even a multiple of 1), especially on an RTOS.

But it is a good idea to limit how many threads you spawn, because they can have significant overhead.

1 Like

There isn’t a maximum total threads however your CPU can only run CPU core number threads at the same time, most CPUs have the ability to rapidly switch between threads to fake more parallelism, this is usually for 2 threads per core. ofc the os also switches threads on cores periodically

you are talking about hyper-threading
Two notes:

  • it’s transparent for programmer
  • we disabled it in our systems :rofl:

ik what its called, there is no reason to delegate such a simple thing to a google search

link removed upon your request

I was saying that there is no reason not to explain hyprthreading when it’s so simple (instead of naming/linking it). I probably should have specified what it was called, though. I also worded my reply very bad lol.

I think all OSes have this limitation in practise.

i just add links everywhere like salt

1 Like

Years ago I attended a demonstration of the BeOS. They had it running on a state-of-the-art Mac clone sporting a PPC 604 (iirc). The demo program that impressed the crowd most was the spinning 3D teapot. According to the presenter, they were spawning a new thread for every frame of the animation.