471,570 Members | 947 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Communication between threads

Hi all

i got an asignment where is should simulate 1000 clients connecting to
a server via TCP, and each client has it's own sequence of data
exchanged so i have to have 1000 threads, so my bigest problem is how
can these threads communicate with each other something like this
Thread1 registers in the mailing system
Thread1 constantly monitores his mailbox
Thread2 registers in the mailing system
and he also checks his mailbox
then he sends a message HELLO to Thread1 which is in the mail
office recognized as RECIPIENT: thread1

Thread1 takes out his message and posts this back....

And this messages can be processed between all 1000 threads so it must
be fast

is there any mechanism in C# something like
Register thread1 as thread1

then thread2 says POSTMESSAGE (thread1, object message)

and thread 1 check message as PeekMessage(thread1, object
returnmessage)

Hope someone can help

Thank you!

Feb 8 '06 #1
1 2396
<al*********@gmail.com> wrote:
i got an asignment where is should simulate 1000 clients connecting to
a server via TCP, and each client has it's own sequence of data
exchanged so i have to have 1000 threads, so my bigest problem is how
can these threads communicate with each other something like this
Thread1 registers in the mailing system
Thread1 constantly monitores his mailbox
Thread2 registers in the mailing system
and he also checks his mailbox
then he sends a message HELLO to Thread1 which is in the mail
office recognized as RECIPIENT: thread1

Thread1 takes out his message and posts this back....

And this messages can be processed between all 1000 threads so it must
be fast

is there any mechanism in C# something like
Register thread1 as thread1

then thread2 says POSTMESSAGE (thread1, object message)

and thread 1 check message as PeekMessage(thread1, object
returnmessage)


Just use a Queue (or similar) that both threads have access to,
remembering to lock appropriately to avoid data races, volatility
problems etc.

If you want to wait until a message arrives, you can use a classic
producer/consumer pattern. See half way down
http://www.pobox.com/~skeet/csharp/t...eadlocks.shtml

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 8 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ayende Rahien | last post: by
9 posts views Thread by Emmanuel Charruau | last post: by
3 posts views Thread by Bryan Christopher | last post: by
21 posts views Thread by dast | last post: by
2 posts views Thread by ne.seri | last post: by
6 posts views Thread by Jck | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

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.