Is Multi-threading necessary?

This is a discussion on Is Multi-threading necessary? within the Networking/Device Communication forums, part of the General Programming Boards category; I have some questions about networking. This isn't specific to any particular socket api, just theoretical. To create a 2-way ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    81

    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:

    Code:
    "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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User Tommo's Avatar
    Join Date
    Jun 2007
    Location
    Scotland
    Posts
    101
    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, 08: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

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