cond_var with proper reentry condition