dwhitney67
May 30th, 2008, 06:25 AM
Today I was asked a (simple) question about how I would design a server to support receiving data from multiple clients (via TCP).
I have resolved a similar problem to this in the past... more than 7 years ago... however I cannot remember the design I settled on.
My main concern is not so much on how to start a new thread for a client that connects, but instead on how to get the parent thread to "join" with a child thread when it terminates, and yet at the same time field (potentially) new connections from additional clients.
Since it is quite possible that the server would have N-number of child-threads running, is there an easy way to join with any thread? Bear in mind that the threads may not necessary behave in a "FIFO" fashion... in other words, it cannot be assumed that the first thread started will be the first to end.
To summarize, what I need is a "join-any" construct. The pthread library provides the pthread_join() function, but this works only on a per thread basis. How can I monitor (join) with any random thread that terminates?
Any thoughts?
P.S. I wish I could change the thread title... I really don't care about spawning... it's the capturing of the end-life of a thread that really matters.
I have resolved a similar problem to this in the past... more than 7 years ago... however I cannot remember the design I settled on.
My main concern is not so much on how to start a new thread for a client that connects, but instead on how to get the parent thread to "join" with a child thread when it terminates, and yet at the same time field (potentially) new connections from additional clients.
Since it is quite possible that the server would have N-number of child-threads running, is there an easy way to join with any thread? Bear in mind that the threads may not necessary behave in a "FIFO" fashion... in other words, it cannot be assumed that the first thread started will be the first to end.
To summarize, what I need is a "join-any" construct. The pthread library provides the pthread_join() function, but this works only on a per thread basis. How can I monitor (join) with any random thread that terminates?
Any thoughts?
P.S. I wish I could change the thread title... I really don't care about spawning... it's the capturing of the end-life of a thread that really matters.