Why do I get an error code everytime I create a thread?