First implementation of waitForThreadCompletion