Terminate threads which run out of code to execute