Re: Using too many threads?



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.

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.

If we subscribe to the 1/10th second rule for GUI response (or even
bring it up to date and make it the 1/1000th of a second), you should
still be able to do the socket send from your GUI thread. If this is
too ugly for you, then create a new thread which listens to a queue.
Have the GUI post its "sent" messages to the queue and the unique thread
will service them on demand.

OS/2's implementation of threads is one of the best in existence! Don't
be afraid to make excessive use of them when it helps your design and
app behavior.

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.

Make a new thread that does a DosSleep(5) and then sends the refresh.
If for some bizarre reason, you have to serialize your network IO
operations, use a mutex semaphore.

--
Reverse the parts of the e-mail address to reply by mail.
.



Relevant Pages

  • Re: Socket sending problems
    ... Repeating the command after ... I'm only seeing data in the send queue of the!NOTIgor socket and SendTest ... So if connection stalls for any reason, ...
    (comp.sys.acorn.programmer)
  • Re: Why does SocketServer default allow_reuse_address = false?
    ... My problem (and the reason I set reuse to True) is this: ... connections active when I restart my service, upon restart, the socket will ... fail to bind because there is still a connection in a WAIT state. ... serve_forever until it doesn't throw a "can't bind to socket" exception. ...
    (comp.lang.python)
  • Re: non blocking sockets
    ... socket), but I think there have been cases where we were stumped as to ... the reason, and chalked it up to flukes in the kernel implementation. ... So the common wisdom is to always use non-blocking I/O along with ...
    (comp.unix.programmer)
  • I think I find it !
    ... You right - the sender close the socket (for other bug reasons that I still ... |> the reason i believe you are losing data is the exact reason that i ... |>> return of endrecv is zero. ... |>>> sent, but you may receive the same datagram more than once, not at ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Force close of file descriptor from command-line
    ... Sorry yes, from the shell. ... No there's no reason for not closing socket, it was a mistake in the ... program is running perfectly (performing data gathering and processing) ...
    (comp.unix.programmer)

Loading