The obvious problem here is that creating a thread or forking a subprocess completes immediately and the main thread continues, then exits at the end of the script while the children are waiting at sleep 300. When the main thread exits the process, Windows kills the other threads.
The main thread didn't continue because the part of the code I showed was running in an indefinite loop. And nothing in the child processes or in the worker threads was executed either.
For a solution, try either wait/waitpid or the ->join() method in threads instead of detaching your worker threads.
I think I tried threads without detaching them. And since the part of the program is in an indefinite loop, I don't want to wait the processes to finish because the loop needed to be fast.