Thread: Information regarding Threads

  1. #1
    Registered User
    Join Date
    Mar 2011

    Information regarding Threads

    I have a server that can handle only ONE client. The client gets authenticated, then the client can store information and perform a bunch of other stuff

    Now, I have to make my server compatible to multiple clients.. up to 10 clients.
    and the clients can work simultaneously with out knowing each other.

    How should i implement threads. I just want a suggestion

  2. #2
    Join Date
    Aug 2010
    Ontario Canada
    On which operating system?

    Different OSs handle threads in differing ways....

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Don't use threads at first - learn to multiplex within a single thread using select/poll and non-blocking I/O.


  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    Quote Originally Posted by Codeplug View Post
    Don't use threads at first - learn to multiplex within a single thread using select/poll and non-blocking I/O.

    Ditto! A server can connect to multiple clients, each with it's own connection. You use select() to wait for a message from any of the clients and deal with them as they come in.

    The only reason to use threads/parallelism is if the server is to perform some time consuming process occasionally and you don't want to leave anyone waiting. In that case, it is this processes which forks off -- there is still only one server listening on one socket. Even apache works that way: there is a main process which handles all incoming calls, and acts like a switchboard for children who perform tasks.

    Remember, even with threads working "simultaneously" is sort of an illusion. It is really a matter of cycling quickly between short tasks. A server loop using select accomplishes much the same thing:

    while (1) {
          select();    // wait for a message
          /* here's where you sort the messages out according to content and origin,
              handing off to whatever functions are appropriate */
    Last edited by MK27; 03-27-2011 at 09:28 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to parallel threads
    By nabi in forum C Programming
    Replies: 0
    Last Post: 09-19-2010, 12:44 PM
  2. Binary was not built with debug information.
    By studentffm in forum C++ Programming
    Replies: 2
    Last Post: 01-25-2010, 12:13 PM
  3. clock()
    By C_ntua in forum C Programming
    Replies: 19
    Last Post: 10-08-2008, 11:45 AM
  4. Yet another n00b in pthreads ...
    By dimis in forum C++ Programming
    Replies: 14
    Last Post: 04-07-2008, 12:43 AM
  5. Assignment Help !! (Student information system)
    By ashb in forum C++ Programming
    Replies: 6
    Last Post: 03-12-2005, 05:32 AM

Tags for this Thread