Re: Multithread safety



Eugene Gershnik wrote:
> Nathan Evans wrote:
>> You got me quite worried then :-)
>
> Well given m's point and thinking some more I will have to go back to my
> original statement. You must synchronize calls to WSARecv in one way or
> another. Otherwise it is impossible to correctly reassemble read results
> after completion notification. Same story (streams are not thread safe)
> but with a different twist.

Sort of.

If your protocol is TCP, then yes, you need to reassemble the read results.

If your protocol is UDP, then it depends on the protocol at the next layer
up, as to whether you need to assemble anything.

TCP is, by its nature, a serial protocol per-socket - as such, it makes very
little sense to consider multiple threads reading from the same socket at
the same time. Multiple threads writing to the same socket - now that is
something that might make sense, but there are some caveats there. You
should generally use a mutex to prevent two writes on the same socket from
interfering.

This is true even for an overlapped socket, because the WSASend() calls
might find their data is interleaved.

I know, not what you wanted to hear - you wanted to hear that Microsoft had
done this work for you. Sadly, no.

Alun.
~~~~
[Please don't email posters, if a Usenet response is appropriate.]
--
Texas Imperial Software | Find us at http://www.wftpd.com or email
23921 57th Ave SE | alun@xxxxxxxxxx
Washington WA 98072-8661 | WFTPD, WFTPD Pro are Windows FTP servers.
Fax/Voice +1(425)807-1787 | Try our NEW client software, WFTPD Explorer.


.



Relevant Pages

  • HEADS UP: network stack and socket hackery over the next few weeks
    ... Over the next few weeks, I'll be doing a fairly serious workworking of the socket and protocol reference models, in order to clean up a number of long-standing race conditions and provide infrastructure for significant locking optimizations for several protocols (including TCP). ...
    (freebsd-current)
  • Re: socket arguments
    ... a protocol argument of zero means unspecified. ... socket type, protocol) parameters. ... ProviderFlags: MatchesProtoZero ...
    (microsoft.public.win32.programmer.networks)
  • Re: sosend/soreceive consistency improvements
    ... As part of cleanups, locking, and optimization work, I've been looking at ... protocol could provide substitute implementations. ... There's another side to the pluggability, however -- the socket consumers ... New references to sosend() and soreceiveperiodically ...
    (freebsd-arch)
  • Re: CAsyncSocket on vista
    ... The error you are getting is WSAEAFNOSUPPORT - Address Family Not ... Perhaps when you are setting up your socket you are not initialising all ... WSAEAFNOSUPPORT Address family not supported by protocol family. ... Conversation: CAsyncSocket on vista ...
    (microsoft.public.vc.mfc)
  • Re: Historical question
    ... Why was it decided that NICs don't have ... >Another use would be for sniffing traffic by doing cat on the socket. ... for 'protocol' identifier. ... Also, by standard implementation, filesystem resources are 'shared access' ...
    (comp.unix.bsd.freebsd.misc)