473,387 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Thread Synchronisation question

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.
Nov 16 '05 #1
3 1169
check out the classes 'System.Threading.AutoResetEvent'
System.Threading.ManualResetEvent'

HTH

Ollie Riches

aveen Mukkelli" <Na************@discussions.microsoft.com> wrote in message
news:F4**********************************@microsof t.com...
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.

Nov 16 '05 #2
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);

"Naveen Mukkelli" <Na************@discussions.microsoft.com> a écrit dans le
message de news:F4**********************************@microsof t.com...
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.

Nov 16 '05 #3
Ludovic SOEUR <Lu***********@hotmail.com> wrote:
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...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ajay | last post by:
hi! my application consists of a GUI with a number of functions. One of these runs a server in a separate thread. the thread is started and given the function start_server to execute the...
2
by: shishir | last post by:
Please validate the followings: STL is thread safe at class level. Iostream library is thread safe at object level. what does it mean and how is it useful for the programmers.
10
by: Support | last post by:
This doubt is regarding synchronisation question in Singleton pattern code of C# I had created a class as public sealed class SecuriteManager { private static volatile SecurityManager...
9
by: Dave G | last post by:
The unexpected problem is this - say, 2 pcs called A and B, both running my Access program, both arranged in a FE/BE arrangement. There is an unbound form in the program. When the form opens all...
6
by: Extremest | last post by:
I am new to threading and trying to figure some things out. Are all variables in a thread set to only that thread? Meaning if I create 2 instances of a class and then put each one in a different...
3
by: =?Utf-8?B?TWFyayBDaGFubmluZw==?= | last post by:
I have a code which registers all threads with a thread dump class. At intervals this thread dump class will dump the stack trace of all threads. As calling StackTrace(threadtoDump) from a...
3
by: fniles | last post by:
I am using VB.Net 2005. My main program calls 2 thread, say thread A and B. I would like to use an array (or arraylist) that will be shared and modified by all the main program, thread A and B....
19
by: Hapa | last post by:
Does only reading (never writing) of a variable need thread synchronisation? Thanks for help? PS. Anybody knows a Visual C++ news group?
8
by: Markus | last post by:
Hello everyone. Recently I stumbled upon an interesting problem related to thread-parallel programming in C (and similarily C++). As an example assume a simple "buffer" array of size 8, e.g....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.