Is there a way to limit threads in Rust? I need to write a program that allows parallelism up to 30 threads, but honestly I have no idea how to that.
There are also other threadpool implementations that are probably also good but I haven't used them.
First off: You start the threads, so why don't you keep track of them with a
AtomicUsize (or similar) and delaying starting new threads until the number is below 30 again?
Second: do you know rayon? There you can use the
RAYON_NUM_THREADS environment variable to limit the number of threads.