Skip to content

The thread safety of RunCallback #189

@ZiyueHuang

Description

@ZiyueHuang

Is KVWorker::RunCallback thread safe?

According to iterator invalidation rules, 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions