added locks and condition variable