diff --git a/include/ps/kv_app.h b/include/ps/kv_app.h index 50bdde6b..914112d8 100644 --- a/include/ps/kv_app.h +++ b/include/ps/kv_app.h @@ -640,18 +640,16 @@ void KVWorker::Process(const Message& msg) { } template void KVWorker::RunCallback(int timestamp) { + Callback cb = nullptr; mu_.lock(); auto it = callbacks_.find(timestamp); if (it != callbacks_.end()) { - mu_.unlock(); - - CHECK(it->second); - it->second(); - - mu_.lock(); + cb = it->second; + CHECK(cb); callbacks_.erase(it); } mu_.unlock(); + if (cb) cb(); } template