Re: Using too many threads?
- From: Marty <net@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 09 Jul 2009 21:37:30 -0700
Alex Taylor wrote:
On Mon, 6 Jul 2009 20:12:38 UTC, Marty <net@xxxxxxxxxxxxxxxxxxx> wrote:
The listen loop needs to be able to do additional processing at regularSounds like a separate thread to me then! Why does this processing have
intervals, though. And I just don't think there's any way to avoid
that.
to be married to the listener?
I guess it's just the way I designed my program. Because I'm dealing with
so many threads, and am so new at it, I set down some rules for myself:
- Only the main window thread may update the main window GUI.
- Only the details window thread may update the details GUI.
- Only the client threads may read to or write from the socket for that
client.
etc.
Is it safe for multiple threads to be reading/writing the same socket?
I would envision this task as follows:
1 GUI thread:
This is a pure "dumb" GUI thread, receives messages on what it should
display and sends commands initiated by the user to the appropriate
worker threads.
1 "connection controller" thread per connection:
This thread exists to post messages to the GUI details windows,
maintains the length of time needed for refreshes/keep-alives/etc.
whatever the protocol demands periodically. Sends across the sockets.
Posts to the GUI. If the GUI messages and keep-alives need to be done
on different timings, then perhaps even split these operations into two
distinct threads. Use a thread control block when launching the thread
to keep all of the threads associated with each other and using the same
data.
1 receiver thread per connection:
Does nothing other than a blocking receive and assembling the data as it
goes. Probably per the protocol it needs to send some information back
across the connection too after receiving some data or to request new data.
As long as your writes are "atomically sound" (no partial data on a
given "send"), then it doesn't matter if multiple threads write to the
socket. If you can't guarantee this, use a mutex semaphore when writing
to the socket in order to make the operations "atomic".
At a minimum, you definitely want to get out of the business of having
multiple PM threads. Trust me on that. It can be done by simply
posting user-defined window messages to instruct the window procedure to
display your data.
--
Reverse the parts of the e-mail address to reply by mail.
.
- Follow-Ups:
- Re: Using too many threads?
- From: Steven Levine
- Re: Using too many threads?
- References:
- Using too many threads?
- From: Alex Taylor
- Re: Using too many threads?
- From: Marcel Müller
- Re: Using too many threads?
- From: Marty
- Re: Using too many threads?
- From: Alex Taylor
- Re: Using too many threads?
- From: Marty
- 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