c++ - Correct way to diagnose mutex-related bottlenecks -


i'm working on application in shared data structure (an std::map) both read , updated multiple threads. number of elements in map fixed @ initialization, values change keys not. use mutex , scoped lock, both provided boost, protect access:

std::map<key,value> datamap; boost::mutex m;  void set(key k, value v) {   boost::scoped_lock sl(m);   datamap[k] = value; }  value get(key k) {   boost::scoped_lock sl(m);   return datamap[k]; } 

how determine if access map bottleneck? seems logical me time how long takes acquire mutex in each case, e.g.

void set(key k, value v) {   timer t; t.start();   boost::scoped_lock sl(m);   t.stop();   cout << "time taken acquire mutex: " << t.elapsed() << endl;   datamap[k] = value; } 

i expect that, when there low contention, average time taken should low, , contention increases (e.g. when there large number of threads), average time taken increase.

is valid way of diagnosing whether access mutex bottleneck?

if not, there open-source programs perform similar functionality correctly?

i'm not sure use small test, if you're program grows can recommend intel inspector threading error analysis, it's not free we've found worth it. has 30-day free trial download run std::map tests on guess.

http://software.intel.com/en-us/intel-inspector-xe


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -