Hey y'all, I'm making a toy renderer, trying to use as much pure rust as possible. Things have been going fairly well, except recently I've added multithreading to the project. It boils down to taking every pixel I want to render and casting out a ray on individual threads.
The problem is, whenever I run 34225+ threads (185 by 185 threads minimum), I get a fairly illegible error that I was hoping someone might shed light on: thread 'main' panicked at 'failed to spawn thread: Os { code: 11, kind: WouldBlock, message: "Resource temporarily unavailable" }', /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/thread/mod.rs:717:29 It is worth mentioning that according to /proc/sys/kernel/threads-max I have a total of 123033 threads, so I shouldn't be running out.
My initial guess is that it might be caused by it filling up memory, but when running htop it doesn't appear that there is much of anything going on when I run it.
Upon further (light) investigation with RUST_BACKTRACE, I found that the last place in my own code that there was an issue is when I call thread::spawn(), then the traceback goes into the standard lib and deeper
If anyone has any ideas, that would be much appreciated, thanks
I should note- what I have is not the best solution, one of my friends when I was discussing this issue suggested only making a thread per cpu core (or whatever it's called, hardware threads, for example my cpu has 16 of them), which would fix the issue, but at this point I'm more curious about the error, and would like to avoid it in the future