C# 4 Multithreading Help

This is a discussion on C# 4 Multithreading Help within the C# Programming forums, part of the General Programming Boards category; I understand the basics of multithreading and synchronization but I cant wrap my head around the way to implement what ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    23

    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,755
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597
    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Net 4 introduces new Concurrent collections that simplify (theoretically) access to the collections in multi-threading environment
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597
    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, 01:12 PM
  2. Multithreading?
    By John Gaden in forum C++ Programming
    Replies: 9
    Last Post: 08-24-2008, 01:50 PM
  3. Multithreading
    By JaWiB in forum Game Programming
    Replies: 7
    Last Post: 08-24-2003, 10:28 PM
  4. Multithreading
    By Lord CyKill in forum C++ Programming
    Replies: 4
    Last Post: 06-30-2003, 12:14 PM
  5. Multithreading
    By -KEN- in forum C# Programming
    Replies: 4
    Last Post: 06-13-2003, 11:11 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21