Pthreads join

S

Simon Timms

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!
 
C

CBFalconer

Simon said:
.... 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.
 
A

Allin Cottrell

Simon said:
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.
 
S

Simon Timms

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.
 
N

nobody

[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? ;-)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top