The thread safety of `RunCallback`
- Dominant language
- C++
- Stars
- 1.6k
- Forks
- 540
- PR merge metrics
- No merged PRs in 30d
Description
Is [KVWorker::RunCallback](https://github.com/dmlc/ps-lite/blob/master/include/ps/kv_app.h#L643-L654) thread safe?
According to [iterator invalidation rules](https://stackoverflow.com/questions/6438086/iterator-invalidation-rules-for-c-containers), rehashing invalidates the iterators of `unordered_map`, which may occur during the execution of the callback (`it->second();`). I didn't encounter any error about "invalid iterator" in my application, but I think it would be better to fix this,
```
Callback cb = nullptr;
mu_.lock();
auto it = callbacks_.find(timestamp);
if (it != callbacks_.end()) {
cb = it->second;
CHECK(cb);
callbacks_.erase(it);
}
mu_.unlock();
if (cb) cb();
```
cc @eric-haibin-lin
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.