Ask a Question related to UNIX Programming, Design and Development.
-
John Galt #1
multiple threads read() problems
Hello,
I have a multi-threaded echo server designed like so:
- there's a main threads and some number of worker threads
(threadpool)
- main thread periodically (every 200 ms) does a select() over client
sockets
- depending on select(), main thread either does accept() or sends a
message
to the worker thread pool (using POSIX message queues)
- worker threads are in a loop waiting to mq_receive(); upon getting a
message
they read() from the client socket (which was indicated in the
message) and write() it back exactly to the client socket
All this is on Solaris 8 SPARC, using gcc with -lsocket -lpthread
-lrt, and using plain vanilla SOCK_STREAM sockets.
The behavior I am seeing on two clients is (imagine a timeline growing
downward):
client A client B
connects connects
sends message1 sends message1
gets echo
sends message2 sends message2
gets echo
disconnects
gets echo of strcat(message1, message2)
In other words, the second client does not get *any* response back
until the first client has disconnected. Needless to say, this sucks.
I am looking for answers/explanations for the following questions:
1. Why does the second client have this "hysteresis" effect?
2. Is there a better way - than mq_xxx - to send messages to a
threadpool?
3. All of the sockets (listening socket, client sockets) are plain
vanilla SOCK_STREAM sockets. Should I be setting some flags on them?
4. Should the worker threads read() or write() differently, e.g. with
flags or other use some other function?
5. The number of threads in the threadpool is arbitrary. It's usually
5-10. Will it go faster if there are more threads? Is there a
threshold?
6. What's a good way to debug multi-threaded processes? (I'm using
lots and lots of printfs.) Is there a debugger that can pinpoint the
timeline more or less accurately?
Thanks in advance!
John
John Galt Guest
-
Action Script to read multiple datasets in XML doc forFlash Bar Chart
I am trying to compare groups of items using an XML source and need assistance in creating the Action Script to properly read multiple datasets... -
to read multiple cfreturn
Hi All, I'm just exploring the CF component function. I've face oe problem which is to read more than1 cfreturn. Here the code and file name : ... -
cf7 installation problems?? read this !!
after installing and uninstalling cf7 4x and not even get passed the setup of my browser IE (security problems) i have tried absolutly everything... -
Blocking on multiple threads with timeout
I have a few threads that might need as long as a minute or more to complete and terminate. If they exceed an arbitrary time, they can be... -
Using a trace function with multiple threads
Hello all, I'd like to know if the set_trace_func function works on a "per thread" basis or if it works globally. I have a multithreaded... -
David Schwartz #2
Re: multiple threads read() problems
"John Galt" <johngalt__@hotmail.com> wrote in message
news:216f064.0307080120.145b7f67@posting.google.co m...
No idea, it's probably a bug in your code.> 1. Why does the second client have this "hysteresis" effect?
Since threads share all their memory, you should just put it in a queue> 2. Is there a better way - than mq_xxx - to send messages to a
> threadpool?
that the threads check. Use a mutex and condition variable to protect the
queue and give the workers something to block on.
Just make them non-blocking.> 3. All of the sockets (listening socket, client sockets) are plain
> vanilla SOCK_STREAM sockets. Should I be setting some flags on them?
Nope.> 4. Should the worker threads read() or write() differently, e.g. with
> flags or other use some other function?
No, 5-10 is definitely enough if they don't block.> 5. The number of threads in the threadpool is arbitrary. It's usually
> 5-10. Will it go faster if there are more threads? Is there a
> threshold?
It depends on your platform. Purify is pretty good for some types of> 6. What's a good way to debug multi-threaded processes? (I'm using
> lots and lots of printfs.) Is there a debugger that can pinpoint the
> timeline more or less accurately?
bugs.
DS
David Schwartz Guest



Reply With Quote

