Re: Using too many threads?
- From: Marcel Müller <news.5.maazl@xxxxxxxxxxxxxxx>
- Date: Sun, 05 Jul 2009 10:23:06 +0200
Alex Taylor wrote:
On Sat, 4 Jul 2009 16:11:15 UTC, Steven Levine <steve53@xxxxxxxxxxxxxxxxxxx> wrote:I would have to guess you are using non-blocking sockets. If you have a
socket per thread there's no reason not to block. The only downside to
blocking sockets is that it takes a bit more work to ensure an app will
always shut down quickly and cleanly, when requested.
Correct. I originally planned to use blocking sockets, but quickly discovered that wasn't going to work.
And now you discovered that non-blocking sockets will not work too. It is nearly impossible to limit the CPU usage without an impact on the throughput.
The Ui thread has to be able to send messages to the thread that talks on
the socket, so commands can be sent to the client at the other end on demand.
I also need to take certain actions at specific intervals (for instance,
send a refresh command to the remote client every 5 seconds), and if the
loop only iterates every time data comes in, that timing gets thrown out
the window.
You can use select with a timeout to implement the refresh command. Furthermore sending commands to the same socket from another thread is safe as long as it is done mutual exclusive to send operations of the other threads. Of course you must also ensure the protocol integrity.
If a delay of 5 Seconds is okay you may also check for asynchronous UI commands by the time. A command queue would be helpful.
Marcel
.
- Follow-Ups:
- Re: Using too many threads?
- From: Marty
- Re: Using too many threads?
- References:
- Using too many threads?
- From: Alex Taylor
- Re: Using too many threads?
- From: Steven Levine
- Re: Using too many threads?
- From: Alex Taylor
- Using too many threads?
- Prev by Date: Re: Using too many threads?
- Next by Date: Re: Using too many threads?
- Previous by thread: Re: Using too many threads?
- Next by thread: Re: Using too many threads?
- Index(es):
Relevant Pages
|
Loading