proper parallel synchronization using a condition variable