Thread Synchronisation question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All,

I need to block all my threads at "one statement " in my C# code.
These threads can proceed indipendently after all of the threads reach
this "one statement".

How can we do this. Kindly let me know

Cheers,

Naveen.
 
check out the classes 'System.Threading.AutoResetEvent'
System.Threading.ManualResetEvent'

HTH

Ollie Riches
 
Use a global variable (nThread in the example) that you initialise to the
number of threads you must synchronise. Then, put this 2 lines in each
thread (if they are differents) :
nThread--;
while (nThread>0) Thread.Sleep(0);
 
Ludovic SOEUR said:
Use a global variable (nThread in the example) that you initialise to the
number of threads you must synchronise. Then, put this 2 lines in each
thread (if they are differents) :
nThread--;
while (nThread>0) Thread.Sleep(0);

.... and then watch your system spin if you've got lots of threads.

Sorry, but that's a horrible way of doing it when there are things like
monitors which make it *so* much more efficient...
 
Back
Top