fix deadlock on exit in normal c++ path