roy doron

roy doron

  • NA
  • 33
  • 20.5k

Assign Mutex to each Thread

May 25 2013 11:14 AM
Hello,

I have a function, and i would like to let a list/array of Threads run parallel in it (inorder to protect critical sections in it).

I thought I'd create List<Mutex> and  assign each one to a different Thread:
for( int i =0; i<10; i++)
{ arrmutex[i] = new mutex(); }

and in the function i would like to lock with a  arrmutex.elementAt(someThread).waitOne()  -> a specific variable

It tells me that i cannot do that cause my mutex list is not initialize, AND, the lock wouldn't work..

Can you please help me figure out, how to initialize a list/array of mutexes?

and how to assign each thread a mutex?

Thanks,

Answers (3)