mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* send(), sendmsg(), sendto() not thread-safe
@ 2006-05-15 21:39 Mark A Smith
  2006-05-15 22:24 ` H. Peter Anvin
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Mark A Smith @ 2006-05-15 21:39 UTC (permalink / raw)
  To: linux-kernel


I discovered that in some cases, send(), sendmsg(), and sendto() are not
thread-safe. Although the man page for these functions does not specify
whether these functions are supposed to be thread-safe, my reading of the
POSIX/SUSv3 specification tells me that they should be. I traced the
problem to tcp_sendmsg(). I was very curious about this issue, so I wrote
up a small page to describe in more detail my findings. You can find it at:
http://www.almaden.ibm.com/cs/people/marksmith/sendmsg.html .

Thanks,
Mark A. Smith

PS. I am using the term "thread" in the general sense, this is a problem
independent of pthreads, etc. The problem occurs when two processes
(whether or not they share an address space) send on the same socket (and
some other low-resource conditions exist).


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: send(), sendmsg(), sendto() not thread-safe
  2006-05-15 21:39 send(), sendmsg(), sendto() not thread-safe Mark A Smith
@ 2006-05-15 22:24 ` H. Peter Anvin
  2006-05-15 22:49 ` David S. Miller
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: H. Peter Anvin @ 2006-05-15 22:24 UTC (permalink / raw)
  To: linux-kernel

Followup to:  <OFE8460E54.0C8D85D8-ON8525716F.0074F22F-8825716F.0076D537@us.ibm.com>
By author:    Mark A Smith <mark1smi@us.ibm.com>
In newsgroup: linux.dev.kernel
>
> I discovered that in some cases, send(), sendmsg(), and sendto() are not
> thread-safe. Although the man page for these functions does not specify
> whether these functions are supposed to be thread-safe, my reading of the
> POSIX/SUSv3 specification tells me that they should be. I traced the
> problem to tcp_sendmsg(). I was very curious about this issue, so I wrote
> up a small page to describe in more detail my findings. You can find it at:
> http://www.almaden.ibm.com/cs/people/marksmith/sendmsg.html .
> 
> Thanks,
> Mark A. Smith
> 
> PS. I am using the term "thread" in the general sense, this is a problem
> independent of pthreads, etc. The problem occurs when two processes
> (whether or not they share an address space) send on the same socket (and
> some other low-resource conditions exist).
> 

User error.  Writes onto a streaming socket (or a pipe) are
thread-safe, *but not necessarily atomic*, if the size exceeds PIPE_BUF.

If you want atomicity you either have to do your own locking, or use a
DGRAM or SEQPACKET socket.

	-hpa


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: send(), sendmsg(), sendto() not thread-safe
  2006-05-15 21:39 send(), sendmsg(), sendto() not thread-safe Mark A Smith
  2006-05-15 22:24 ` H. Peter Anvin
@ 2006-05-15 22:49 ` David S. Miller
  2006-05-16  2:47 ` David Schwartz
  2006-05-16 20:09 ` Christoph Hellwig
  3 siblings, 0 replies; 5+ messages in thread
From: David S. Miller @ 2006-05-15 22:49 UTC (permalink / raw)
  To: mark1smi; +Cc: linux-kernel, netdev

From: Mark A Smith <mark1smi@us.ibm.com>
Date: Mon, 15 May 2006 14:39:06 -0700

> I discovered that in some cases, send(), sendmsg(), and sendto() are not
> thread-safe. Although the man page for these functions does not specify
> whether these functions are supposed to be thread-safe, my reading of the
> POSIX/SUSv3 specification tells me that they should be. I traced the
> problem to tcp_sendmsg(). I was very curious about this issue, so I wrote
> up a small page to describe in more detail my findings. You can find it at:
> http://www.almaden.ibm.com/cs/people/marksmith/sendmsg.html .

I don't understand why the desire is so high to ensure that
individual threads get "atomic" writes, you can't even ensure
that in the general case.

Only sloppy programs that don't do their own internal locking hit into
issues in this area.

>From your findings, the vast majority of systems you investigated do
not provide "atomic" thread safe write semantics over TCP sockets.
And frankly, BSD defines BSD socket semantics here not some wording in
the POSIX standards.

Finally, this discussion belongs on the networking development mailing
list, netdev@vger.kernel.org, not linux-kernel.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: send(), sendmsg(), sendto() not thread-safe
  2006-05-15 21:39 send(), sendmsg(), sendto() not thread-safe Mark A Smith
  2006-05-15 22:24 ` H. Peter Anvin
  2006-05-15 22:49 ` David S. Miller
@ 2006-05-16  2:47 ` David Schwartz
  2006-05-16 20:09 ` Christoph Hellwig
  3 siblings, 0 replies; 5+ messages in thread
From: David Schwartz @ 2006-05-16  2:47 UTC (permalink / raw)
  To: linux-kernel


> I discovered that in some cases, send(), sendmsg(), and sendto() are not
> thread-safe. Although the man page for these functions does not specify
> whether these functions are supposed to be thread-safe, my reading of the
> POSIX/SUSv3 specification tells me that they should be. I traced the
> problem to tcp_sendmsg(). I was very curious about this issue, so I wrote
> up a small page to describe in more detail my findings. You can 
> find it at:
> http://www.almaden.ibm.com/cs/people/marksmith/sendmsg.html .
> 
> Thanks,
> Mark A. Smith

	You are confusing thread-safety with atomicity.

	DS



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: send(), sendmsg(), sendto() not thread-safe
  2006-05-15 21:39 send(), sendmsg(), sendto() not thread-safe Mark A Smith
                   ` (2 preceding siblings ...)
  2006-05-16  2:47 ` David Schwartz
@ 2006-05-16 20:09 ` Christoph Hellwig
  3 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2006-05-16 20:09 UTC (permalink / raw)
  To: Mark A Smith; +Cc: linux-kernel

On Mon, May 15, 2006 at 02:39:06PM -0700, Mark A Smith wrote:
> 
> I discovered that in some cases, send(), sendmsg(), and sendto() are not
> thread-safe. Although the man page for these functions does not specify
> whether these functions are supposed to be thread-safe, my reading of the
> POSIX/SUSv3 specification tells me that they should be. I traced the
> problem to tcp_sendmsg(). I was very curious about this issue, so I wrote
> up a small page to describe in more detail my findings. You can find it at:
> http://www.almaden.ibm.com/cs/people/marksmith/sendmsg.html .

Please don't confuse thread safety with atomicy, thanks.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-05-16 20:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-15 21:39 send(), sendmsg(), sendto() not thread-safe Mark A Smith
2006-05-15 22:24 ` H. Peter Anvin
2006-05-15 22:49 ` David S. Miller
2006-05-16  2:47 ` David Schwartz
2006-05-16 20:09 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®