correct synchronization when terminating