Tighter threading using condition variable.