Re: Multithread safety



Mike Gleason Jr Couturier wrote:
> I have another question concerning this topic...
> (multithread & blocking sockets)
>
> Is it considered an acceptable practice to create a
> second thread that do blocking reads (recv) and quits
> only if it detects a socket error (like when the main thread
> closes the socket).

Not really. You should investigate various asynchronous I/O mechanisms
instead.

> Is it a bad thing to do ?

Usualy yes. I wouldn't do it in production code.


--
Eugene
http://www.gershnik.com


.



Relevant Pages

  • Re: Question about non-blocking NIO and Selection Keys
    ... around blocking sockets, and without a complete re-write it's hard to ... because we need to support the case where the client can ... asynchronously send a message to the server telling it to stop sending ... socket, and is now scattered across 10s of thousands of lines of code ...
    (comp.lang.java.programmer)
  • Re: BSD sockets: recv with MSG_WAITALL should return EWOULDBLOCK?
    ... (I am not convinced it is much use for blocking sockets ... many bytes as the size argument to recv() or to close the connection after ... system, ie one where the average delay is larger, additional data could ... sometimes be received and queued to the socket buffer during the delay. ...
    (comp.unix.programmer)
  • Re: WSASend returns SOCKET_ERROR but data is sent and bytesSend is updated
    ... workaround with blocking sockets without overlapped IO. ... SOCKET ListenSocket, AcceptSocket; ... // Bind the listening socket to the local IP address ...
    (microsoft.public.win32.programmer.networks)
  • Re: Using too many threads?
    ... socket per thread there's no reason not to block. ... I originally planned to use blocking sockets, ... If we subscribe to the 1/10th second rule for GUI response (or even ... If for some bizarre reason, you have to serialize your network IO ...
    (comp.os.os2.programmer.misc)
  • Re: Using too many threads?
    ... I originally planned to use blocking sockets, but quickly discovered that wasn't going to work. ... the socket, so commands can be sent to the client at the other end on demand. ... loop only iterates every time data comes in, ... 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. ...
    (comp.os.os2.programmer.misc)