Pthreads join

Discussion in 'C Programming' started by Simon Timms, Nov 7, 2003.

  1. Simon Timms

    Simon Timms Guest

    Hi there,
    first let me appologise for my stupidity, I am pretty new to C programming
    and i wouldvalue any pointers you would like to give me (style, spelling...)

    My problem is this, i am trying to build a threaded server for a class.
    I have a pool of threads in an array and i spawn a new thread each time
    that i get a connection. This thread goes off and serves the page and
    headers. My problem is that I need to know when the thread returns so that
    I can free up that thread pointer. I don't think i can use pthread_join
    since it is blocking and i need to be able to send off new threads on
    request. I also cannot use a loop looking through the threads and checking
    them for termination (not that i know how to check for terminiation anyway)
    since i have a accept(2) which is blocking.

    while(1)
    {
    connections[connection_place] = accept(master_fd,
    (struct sockaddr *) & addr, &len);
    pthread_create(&thread_pool[connection_place], NULL,
    handle_connection, &(connections[connection_place]));
    connection_place++;
    }

    Right now the code is just looping through the thread_pool and connections
    arrays but eventually i want to look for places where the connection is
    NULL and use that spot.

    What would you suggest?

    Thanks!

    --
    "Computing Science n : the branch of engineering science that
    studies (with the aid of computers) computable processes and structures
    See also: 'Gong Show'"
     
    Simon Timms, Nov 7, 2003
    #1
    1. Advertising

  2. Simon Timms

    CBFalconer Guest

    Simon Timms wrote:
    >

    .... snip ...
    >
    > My problem is this, i am trying to build a threaded server for a
    > class. I have a pool of threads in an array and i spawn a new

    .... snip ...
    >
    > What would you suggest?


    Start by realizing that threads have nothing to do with the C
    language, but have everything to do with your operating system.
    Therefore you should be asking in a newsgroup that deals with that
    system, or with threads in general. In addition, there is no such
    thing as a class in C, although there is in C++ (but no threads).
    So don't move to the C++ newsgroup.

    --
    Chuck F () ()
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net> USE worldnet address!
     
    CBFalconer, Nov 7, 2003
    #2
    1. Advertising

  3. Simon Timms wrote:
    > Hi there,
    > first let me appologise for my stupidity, I am pretty new to C programming
    > and i wouldvalue any pointers you would like to give me (style, spelling...)
    >
    > My problem is this, i am trying to build a threaded server for a class.
    > I have a pool of threads in an array and i spawn a new thread each time
    > that i get a connection....
    >
    > What would you suggest?


    I'm afraid I would suggest a different newsgroup -- say
    comp.unix.programmer if your threads are in a unix-type environment.
    The problem is that threads are not part of standard C, which is
    what this group is about.

    --
    Allin Cottrell
    Department of Economics
    Wake Forest University, NC
     
    Allin Cottrell, Nov 7, 2003
    #3
  4. Simon Timms

    Simon Timms Guest

    In article <>, CBFalconer wrote:
    > Simon Timms wrote:
    >>

    > ... snip ...
    >>
    >> My problem is this, i am trying to build a threaded server for a
    >> class. I have a pool of threads in an array and i spawn a new

    > ... snip ...
    >>
    >> What would you suggest?

    >
    > Start by realizing that threads have nothing to do with the C
    > language, but have everything to do with your operating system.
    > Therefore you should be asking in a newsgroup that deals with that
    > system, or with threads in general. In addition, there is no such
    > thing as a class in C, although there is in C++ (but no threads).
    > So don't move to the C++ newsgroup.


    Thanks, I will repost this in another news group. I know there are no
    classes in C, this was a class in the context of school.


    --
    "Computing Science n : the branch of engineering science that
    studies (with the aid of computers) computable processes and structures
    See also: 'Gong Show'"
     
    Simon Timms, Nov 7, 2003
    #4
  5. Simon Timms

    nobody Guest

    "Allin Cottrell" <> wrote in message
    news:bof9ib$3l46$...

    > [snip]
    > I'm afraid I would suggest a different newsgroup -- say
    > comp.unix.programmer if your threads are in a unix-type environment.
    > The problem is that threads are not part of standard C, which is

    ------^^^^^^^^^^
    I beg to differ. I don't see this as a problem, but as a blessing.
    Can you imagine guiding newbies through pointers *and* thread
    synchronization issues at the same time? ;-)
     
    nobody, Nov 9, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. john
    Replies:
    1
    Views:
    584
    Grant Wagner
    Jul 23, 2004
  2. Jim

    java and pthreads

    Jim, Sep 14, 2005, in forum: Java
    Replies:
    0
    Views:
    2,517
  3. Savagesmc
    Replies:
    3
    Views:
    474
    Savagesmc
    Nov 11, 2003
  4. Alan Silver
    Replies:
    0
    Views:
    912
    Alan Silver
    Jun 5, 2006
  5. googleboy
    Replies:
    1
    Views:
    953
    Benji York
    Oct 1, 2005
Loading...

Share This Page