-
C# 4 Multithreading Help
I understand the basics of multithreading and synchronization but I cant wrap my head around the way to implement what I need now. Here is the situation:
I have a multi-client server utilizing the Reactor single thread model. I need a thread to sit and wait for connections and accept them which is simple to do and I understand it.
Now I need a thread to handle all the socket reads but I dont understand how to do this because if I create it from the while loop that is accepting connection it would create one for each connection, but I need to seperate it from that thread else it will block.
I also want another thread for actual processing of the commands and data access. Please explain to me how I can accomplish this.
Thank you very much.
-
Do you know how to create one thread from another thread?
Do you know how to pass input parameters to a newly created thread?
Create some really short test programs to get familiar with passing a parameter (say a socket ID) from one thread to another.
-
The problems that multi-threading introduces also exist in C#. C# has several locking mechanisms and thread mechanisms that assist you when working with threads. I would advise you either do some non-forum based research on the internet or buy a book. C# is pretty straight forward so it may simply require browsing the .NET help to find what you want. AFAIK multi-threading has been greatly simplified in .NET as opposed to Win32. The locks and mutexes still exist and are the same ones in native code but the interface to them has been simplified and is easier to understand.
-
Net 4 introduces new Concurrent collections that simplify (theoretically) access to the collections in multi-threading environment
-
Good information indeed. Thanks.