Skip to content

Provide APIs that accept user passed accessor as a param? #3

@jy5275

Description

@jy5275

I use your excellent implementation of scalable-cache as a counter. The instantiated value type is int. The counter needs to be increase by 1 like this:

template<typename T>
void AddCount(int idx, T key) {
  ScalableCache::ConstAccessor ac;
  if (scala_counter.find(ac, key)) {
    int cnt = *ac;
    scala_counter.insert(key, cnt+1);
  } else {
    scala_counter.insert(key, 1);
  }
}

This causes problem. In find method, accessor is passed by user as a param. While insert method creates its own accessor. Deadlock occurs when insert tries to aquire a lock on key entry but find is still holding it.
There seems to be no graceful solution with current APIs. And the control of accessor may confuse programmers. I think we could add the following APIs:

  bool find(HashMapConstAccessor& ac, const TKey& key);
  bool find(HashMapAccessor& ac, const TKey& key);

  bool insert(const TKey& key, const TValue& value);
  bool insert(HashMapAccessor &ac, const TKey& key, const TValue& value);

With these APIs, programmer could explicitly synchronizes the threads that access the same cache object.
What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions