Fix the saving of context when the context has been removed (thread termination)