$ 0 0 You aren't joining or detaching the threads causing the program to exit with errors. Store the threads in an array so you can join them or call detach in your loop.