All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: send(), sendmsg(), sendto() not thread-safe
@ 2006-05-17 17:25 Benjamin Reed
  2006-05-17 18:00 ` Christopher Friesen
  0 siblings, 1 reply; 16+ messages in thread
From: Benjamin Reed @ 2006-05-17 17:25 UTC (permalink / raw)
  To: netdev

David et al, I think you may be missing the point. 

David S. Miller wrote:
> 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.

I think Mark's point isn't about "atomic" writes;
instead, he was pointing out that when a programmer
reads that a call is thread-safe he usually
understands that to mean that it does not need to be
protected by a lock when used by multiple threads.

With the current implementation of sendmsg it takes
some imagination to come up with scenario where it is
okay for concurrent sendmsg calls to mix their data.

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

You are looking at it backwards. If sendmsg were
indeed
thread-safe (two concurrent calls to sendmsg would not
mix their data), then it would be stupid for a
programmer to put a lock around the sendmsg call. It
would also be stupid for a programmer to protect a
call to socket() with a lock.

This thread-safe issue is an even bigger deal when you
are sharing the socket amoung many independent
processes since locking in that context is a bit
harder and more inefficient than in a pthread context.

So, if it isn't going to be "fixed". It would be nice
to at least document the issue. A cursory examination
of the sendmsg kernel code leads you to believe that
it is thread-safe in the sense that Mark is talking
about.

ben

^ permalink raw reply	[flat|nested] 16+ messages in thread
* 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; 16+ 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] 16+ messages in thread

end of thread, other threads:[~2006-05-17 19:06 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <OFA7F8723C.2DDF9383-ON85257170.00014BE5-88257170.00019BEA@us.ibm.com>
2006-05-16  0:43 ` send(), sendmsg(), sendto() not thread-safe Rick Jones
2006-05-16  1:50   ` Mark A Smith
2006-05-16 16:24     ` Mike Stroyan
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
  -- strict thread matches above, loose matches on Subject: below --
2006-05-15 21:39 Mark A Smith
2006-05-15 22:24 ` H. Peter Anvin
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

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.