ensure releasing the condition variable and the related mutex

when releasing a command