0

My Question: Why is my program freezing if i use "read only" const_accessors?

It seems to be locking up, from the API description it seems to be ok to have one accessors and multiple const_accessors, (writer, reader). Maybe somebody can tell me a different story.

The Goal i try to achieve is to use this concurrent hash map and make it available to 10-200 Threads so that they can lookup and add/delete information. If you have a better solution than the current one i' am using than you also welcome to post the alternatives.

tbb::size_t hashInitSize = 1200000;
concurrent_hash_map<long int,char*> hashmap(hashInitSize);
cout << hashmap.bucket_count() << std::endl;

long int l = 200;
long int c = 201;

    concurrent_hash_map<long int,char*>::accessor o;
    concurrent_hash_map<long int,char*>::const_accessor t;
    concurrent_hash_map<long int,char*>::const_accessor h;

    cout << "Trying to find 200 "<< hashmap.find(t,200) << std::endl;

    hashmap.insert(o,l);
o->second = "testother";

TBB Community Tutorial Guide Page 43 describes the concept of accessors

Oliver
  • 928
  • 9
  • 25

1 Answers1

1

From the TBB reference manual:

An accessor acts as a smart pointer to a pair in a concurrent_hash_map. It holds an implicit lock on a pair until the instance is destroyed or method release is called on the accessor.

Accessors acquire a lock when they are used. Multiple accessors can exist at the same time. However, if a program uses multiple accessors concurrently and does not release the locks, it is likely to deadlock.

To avoid deadlock, release the lock on a hash map entry once you are done accessing it.

Heatsink
  • 7,721
  • 1
  • 25
  • 36
  • thanks for your quick response, so you are saying this only deadlocks because i have not multiple threads on it? Shouldn't this data structure be useable in a concurrent environment and never deadlock? (or is it just waiting for the initial lock to be released?) That would mean, it would be allowed to only access the data-structure sequential in a specific thread and only once per thread? – Oliver Jul 08 '12 at 18:30
  • You can access different entries in parallel, for example, parallel access to entry 200 and entry 201 is okay. You cannot access a single entry in parallel with multiple threads using `accessor`. Your code tries to acquire ownership of entry 200, then acquire ownership of entry 200 again. That is like accessing entry 200 in parallel with two threads. – Heatsink Jul 08 '12 at 18:42