c++ - data write in array in multi-threading environment -


i have block in multi-threaded program following operation:

void func(args){     computation;     for(i = 0; < n ; i++)         value[i] += computed_value;  } 

multiple thread execute function. need make program thread-safe using lock. locking making program slower single threaded program. have tried using lock making program slow. please suggest alternative approaches.

according code, not have locks. i'd use locks instead of no locks start approach. (without more clarification, cannot out much). if can, lock operations inside of computation.

psuedo example

int computation(int i)     lock();     = + 1;     unlock();     return i; 

Comments

Popular posts from this blog

mongodb - Struggling to get ordered results from the last retrieved article, given array of elements to search in -

c# - Pausing a storyboard on TabItem mouse over -

c# - Attribute value in root node of xml Linq to XML -