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