Use yield instead of sleep to wait for threads