Re: Multithread safety
- From: "Eugene Gershnik" <gershnik@xxxxxxxxxxx>
- Date: Mon, 14 Nov 2005 23:07:29 -0800
Alun Jones wrote:
> If your protocol is TCP, then yes, you need to reassemble the read
> results.
This whole discussion was about TCP
> 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.
We are talking about IOCP here. The WSARecv or WSASend are not reads or
writes but rather queued requests. The actual reading is dome by the thread
pool calling GetQueuedCompletionStatus and there can certainly be more than
1 of them. As for WSARecv/WSASend the way they are posted depends on the
protocol and application logic. Except for one case with UDP I always had
them in one thread but these were quirks of what I had to deal with. A
general TCP server may find it convenient to post from multiple threads.
> 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.
Not really. You may want to re-read this thread from the begining to see
that I was making exactly the same points. The confusion in was about IOCP
case specifically. What would be nice for MS to do is to have
GetQueuedCompletionStatusEx return the sequence number of the completion in
the queue. In this case it would be possible to avoid locking on
WSARecv/WSASend. See the nearby subthread for detials.
--
Eugene
http://www.gershnik.com
.
- Follow-Ups:
- Re: Multithread safety
- From: Alun Jones
- Re: Multithread safety
- References:
- Multithread safety
- From: Mike Gleason Jr Couturier
- Re: Multithread safety
- From: Eugene Gershnik
- Re: Multithread safety
- From: Nathan Evans
- Re: Multithread safety
- From: Eugene Gershnik
- Re: Multithread safety
- From: Nathan Evans
- Re: Multithread safety
- From: Eugene Gershnik
- Re: Multithread safety
- From: Eugene Gershnik
- Re: Multithread safety
- From: Nathan Evans
- Re: Multithread safety
- From: Eugene Gershnik
- Re: Multithread safety
- From: Alun Jones
- Multithread safety
- Prev by Date: Re: Changing TTL of incoming packets?
- Next by Date: Re: Changing TTL of incoming packets?
- Previous by thread: Re: Multithread safety
- Next by thread: Re: Multithread safety
- Index(es):
Relevant Pages
|