Thread Synchronisation question

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.
 
O

Ollie Riches

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

HTH

Ollie Riches
 
L

Ludovic SOEUR

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);
 
J

Jon Skeet [C# MVP]

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top