c++ - Correctly using an accessor in tbb -
i have list of items insert tbb's concurrent hash map. what's correct way of using accessor, way 1 or 2?
// way 1 (a list of (keys,values)) { map::accessor a; myhashtable.insert(a, key); (a->second).push_back(value); a.realease(); } // way 2 map::accessor a; (a list of (keys,values)) { myhashtable.insert(a, key); (a->second).push_back(value); a.realease(); }
basically either, since explicitly call accessor::release()
. generally, code quality point of view, i'd limit scope of locking minimal necessary region since code extended further in unexpected way or/and exception-safety issue.
the third way without explicit release is:
// way 3 (a list of (keys,values)) { map::accessor a; myhashtable.insert(a, key); (a->second).push_back(value); }
p.s. try avoid using of accessor in serial code when possible, e.g. use insert(value_type) form. reduce overheads of thread-safety
Comments
Post a Comment