use mutex / condition
removed thread cond
improved thread handling