Correct error handling for thread creation

Error handling corrected for thread creation in case of e.g.
insufficient system resources.