Thread: Is Multi-threading necessary?

  1. #1
    Registered User
    Join Date
    Aug 2007

    Is Multi-threading necessary?

    I have some questions about networking. This isn't specific to any particular socket api, just theoretical. To create a 2-way chat system each client must be able to send and receive data. Ideally, they'd always be waiting for data. When the data comes it'll get output to the screen. Also ideally, they'd always be able to send data. So while data is being received it is also being sent.

    Is it possible to implement this without multi-threading? I'm thinking:

    "chatProcess"'s process descriptor block (PDB)  
    status: blocked  
    reason: waiting for data to be sent, waiting for data to arrive.
    So if data is sent (ie. the user typed in some text and hit enter) the event handler will pass off the message to the send() function. The recv() function would work parallel to this.

    (So if the data sent flag and the data arrive flag were set almost at the exact same time it would be handled by a que, whichever arriving first being processed first)

    As you can see this is not multi-threading. So is this possible on modern operating systems? Or is multi-threading preferred?

    Any articles/books you'd recommend?

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    You can use the select approach
    In this case you application uses asynch socket operations and only 1 working thread

    Of course OS can implement asynch operations and callbacks using additional threads but they are hiddedn from the application
    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

  3. #3
    Registered User Tommo's Avatar
    Join Date
    Jun 2007
    Yes poll() or select() is what you're looking for.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. overlapped I/O and multi threading
    By krishnampkkm in forum C++ Programming
    Replies: 2
    Last Post: 06-22-2009, 03:27 PM
  2. Multi Threading
    By beon in forum C Programming
    Replies: 5
    Last Post: 12-04-2006, 09:21 PM
  3. Replies: 6
    Last Post: 06-02-2006, 08:32 AM
  4. starting to learn multi threading
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2004, 01:44 PM
  5. Multi Threading
    By IceBall in forum C Programming
    Replies: 7
    Last Post: 07-13-2003, 03:01 PM