Thread: C# 4 Multithreading Help

  1. #1
    Registered User
    Join Date
    Mar 2009

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

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    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.

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    Net 4 introduces new Concurrent collections that simplify (theoretically) access to the collections in multi-threading environment
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Good information indeed. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multithreading.
    By kevinawad in forum C++ Programming
    Replies: 5
    Last Post: 10-21-2008, 12:12 PM
  2. Multithreading?
    By John Gaden in forum C++ Programming
    Replies: 9
    Last Post: 08-24-2008, 12:50 PM
  3. Multithreading
    By JaWiB in forum Game Programming
    Replies: 7
    Last Post: 08-24-2003, 09:28 PM
  4. Multithreading
    By Lord CyKill in forum C++ Programming
    Replies: 4
    Last Post: 06-30-2003, 11:14 AM
  5. Multithreading
    By -KEN- in forum C# Programming
    Replies: 4
    Last Post: 06-13-2003, 10:11 PM

Tags for this Thread