Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Pthreads join

Reply
Thread Tools

Pthreads join

 
 
Simon Timms
Guest
Posts: n/a
 
      11-07-2003
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'"

 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      11-07-2003
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 ((E-Mail Removed)) ((E-Mail Removed))
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!

 
Reply With Quote
 
 
 
 
Allin Cottrell
Guest
Posts: n/a
 
      11-07-2003
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

 
Reply With Quote
 
Simon Timms
Guest
Posts: n/a
 
      11-07-2003
In article <(E-Mail Removed)>, 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'"

 
Reply With Quote
 
nobody
Guest
Posts: n/a
 
      11-09-2003
"Allin Cottrell" <(E-Mail Removed)> wrote in message
news:bof9ib$3l46$(E-Mail Removed)...

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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
You must join New York Paid To Read !!!!!!! NewYork PTR is online!!! JOIN NOW!!!!!! Alan Silver ASP .Net 0 06-05-2006 03:27 PM
list.join()... re.join()...? Do they exist? (newbie questions...) googleboy Python 1 10-01-2005 12:56 PM
java and pthreads Jim Java 0 09-14-2005 06:07 PM
JAVA - pthreads - HP-UX 11.0 john Java 1 07-23-2004 04:25 PM
Polymorphism, pthreads, multi-threading, and libstdc++ Savagesmc C++ 3 11-11-2003 03:55 AM



Advertisments