Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

multi-threading and tcp (Is Full duplex thread safe?)

8 views
Skip to first unread message

Spam Hater

unread,
Feb 11, 1999, 3:00:00 AM2/11/99
to

TCP is full duplex. Is it full duplex as far as threading goes? Are
the send and recv channels completely separate and thread safe?
Basically I am trying to ask:
If one thread is reading from a socket via recv(), can another thread
do a send() at the same time? Assume a multi-cpu box.
My main concern is that some how one thread will effect the state of
the socket in such a way that it will interfere or not be safe.

Thanks,
Spam Hater


Mike Vogeleer

unread,
Feb 11, 1999, 3:00:00 AM2/11/99
to
It depends on your OS. Most Unixes are multithread-safe with respect to
threads these days (at least Linux, SunOS and HP-unix are). So sending
from one thread and simultaneously receiving on another one is no
problem (the socket library and the kernel take care of all the
potential interferences).

Check the man page of socket()

Jon C. Snader

unread,
Feb 11, 1999, 3:00:00 AM2/11/99
to
Spam Hater wrote:
>
> TCP is full duplex. Is it full duplex as far as threading goes? Are
> the send and recv channels completely separate and thread safe?
> Basically I am trying to ask:
> If one thread is reading from a socket via recv(), can another thread
> do a send() at the same time? Assume a multi-cpu box.
> My main concern is that some how one thread will effect the state of
> the socket in such a way that it will interfere or not be safe.

A common UNIX paradigm is for a process to fork off a child that handles
(let's say) writing to a socket while the parent handles the reading.
Thus if you are running in a UNIX environment, there should be no
problem reading and writing in different threads.

Jon Snader

0 new messages