All of lore.kernel.org
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: linux-kernel@vger.kernel.org
Subject: Re: send(), sendmsg(), sendto() not thread-safe
Date: Mon, 15 May 2006 15:24:16 -0700 (PDT)	[thread overview]
Message-ID: <e4av2g$ctj$1@terminus.zytor.com> (raw)
In-Reply-To: OFE8460E54.0C8D85D8-ON8525716F.0074F22F-8825716F.0076D537@us.ibm.com

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


  reply	other threads:[~2006-05-15 22:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-15 21:39 send(), sendmsg(), sendto() not thread-safe Mark A Smith
2006-05-15 22:24 ` H. Peter Anvin [this message]
2006-05-15 22:49 ` David S. Miller
2006-05-15 23:17   ` Rick Jones
2006-05-15 23:35     ` Stephen Hemminger
2006-05-16  0:02       ` Rick Jones
2006-05-16  2:47 ` David Schwartz
2006-05-16 20:09 ` Christoph Hellwig
     [not found] <OFA7F8723C.2DDF9383-ON85257170.00014BE5-88257170.00019BEA@us.ibm.com>
2006-05-16  0:43 ` Rick Jones
2006-05-16  1:50   ` Mark A Smith
2006-05-16 16:24     ` Mike Stroyan
  -- strict thread matches above, loose matches on Subject: below --
2006-05-17 17:25 Benjamin Reed
2006-05-17 18:00 ` Christopher Friesen
2006-05-17 18:21   ` Benjamin Reed
2006-05-17 18:52     ` Rick Jones
2006-05-17 19:06       ` Benjamin Reed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='e4av2g$ctj$1@terminus.zytor.com' \
    --to=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.