473,383 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Pthreads join

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'"

Nov 13 '05 #1
4 3835
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 (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!

Nov 13 '05 #2
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

Nov 13 '05 #3
In article <3F***************@yahoo.com>, 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'"

Nov 13 '05 #4
"Allin Cottrell" <co******@wfu.edu> wrote in message
news:bo***********@f1n1.spenet.wfu.edu...
[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? ;-)
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: john | last post by:
Hi, I've heard that the lack of performance of JAVA on HP-UX 11.0 is due to bad implementation of pthreads. It should be solved in HP-UX 11.11. Can anyone tell me if this is true ? thanks,...
0
by: Kevin Dahlhausen | last post by:
I've been playing with pySonic on unix. PySonic is pyrex wrapper around the fmod sound library. Fmod is distributed as a shared library that uses pthreads. I am getting a segfault when a...
5
by: Arnd Schroeter | last post by:
Hello! I am a c++ programmer under the os linux. I am using pthreads and i am wondering why i can only use satic methods of a class to create a thread of it. How can i change this, because it...
15
by: John David Ratliff | last post by:
Maybe someone here can help me. I want to use C++, but pthreads seems to be nonfunctional in it. The following test code I've written in C and C++. The C version works, while the C++ one does...
2
by: Jack | last post by:
hi all I would find a parallel sorting algorithms written with pthread programs, as a benchmark to run. Any pointing will be of help thankyou in advance
2
by: um | last post by:
When the POSIX pthreads library for w32 release 2-2-0 (http://sources.redhat.com/pthreads-win32/) is compiled with VC++6 then it compiles and passes all the benchmark tests in the subdirectory...
5
by: Ed L. | last post by:
Is this pthreads warning of any concern? gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes -Wmissing-declarations -pthread -pthreads -D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS...
8
by: Matt England | last post by:
My team currently using Boost Threads, but we are considering switching to ZThreads. (We seek cross-platform, C++ multithreading capabilities in an external library.) ZThread(s): ...
7
by: duncanedinburgh | last post by:
Hi all. I am trying to spawn four hundred pthreads and I am getting an error from pthread_join() with error code 0. It seems that when the 382nd thread tries to join, there's a segmentation fault. I...
4
by: Neel | last post by:
Hi, I 'm facing some prob with creating pthreads. My requirement is to create threads in a loop. but I dont want to make an array of pthread. At anytime I want to have 5 threads (I used a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.