Communication between threads

A

alen.petrol

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!
 
J

Jon Skeet [C# MVP]

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/threads/deadlocks.shtml
 

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