Re: Multithread safety
- From: "Eugene Gershnik" <gershnik@xxxxxxxxxxx>
- Date: Fri, 4 Nov 2005 11:54:06 -0800
Mike Gleason Jr Couturier wrote:
> I know one can open 2 connections to do a
> simultaneous 2 way connection...
>
> My question is can one thread exclusively read
> on a socket while another exclusively write on it...
Not sure what you mean by exclusively but yes you can read and write
simultaneously.
When discussing multi-threading it is important to first determine what is a
shared "resource" that you are accessing. In case of a TCP socket there are
3 of them
1. The socket object itself
2. The input TCP stream
3. The output TCP stream.
The socket object is thread safe. When you call recv() and send()
simultaneously nothing in the socket internal data structures will break.
The streams are separate resources so again recv() on one and send() on
another are ok.
What is usually not ok is two simultaneous recv()-s or send()-s. They access
the same stream object and any stream is not safe for multiple reads or
writes.
--
Eugene
http://www.gershnik.com
.
- Follow-Ups:
- Re: Multithread safety
- From: Nathan Evans
- Re: Multithread safety
- From: Arkady Frenkel
- Re: Multithread safety
- From: Mike Gleason Jr Couturier
- Re: Multithread safety
- References:
- Multithread safety
- From: Mike Gleason Jr Couturier
- Multithread safety
- Prev by Date: Multithread safety
- Next by Date: Re: Destination host unreachable?
- Previous by thread: Multithread safety
- Next by thread: Re: Multithread safety
- Index(es):
Relevant Pages
|