Ensure critial sections are released before returning