From: "Christopher Friesen" <cfriesen@nortel.com>
To: Benjamin Reed <br33d@yahoo.com>
Cc: netdev@vger.kernel.org
Subject: Re: send(), sendmsg(), sendto() not thread-safe
Date: Wed, 17 May 2006 12:00:52 -0600 [thread overview]
Message-ID: <446B64D4.6080301@nortel.com> (raw)
In-Reply-To: <20060517172557.43768.qmail@web51507.mail.yahoo.com>
Benjamin Reed wrote:
> 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.
<snip>
> 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.
There have always been possible issues with concurrent access to
sockets/fds.
Consider what happens if you share a socket between processes/threads,
you call select() in both of them, then do a blocking recv() in both to
receive the message. One of them gets the message, and the other blocks
unexpectedly.
Or consider calling lseek() from one task, while doing successive read()
calls in the other.
Or imagine one thread doing recvmsg() with MSG_PEEK, then calling
recvmsg() to get the data, but meanwhile another thread has already read
the message.
The calls themselves are thread-safe, but the side-effects of them may
lead to unexpected behaviour unless the designer enforces appropriate
synchronization.
Chris
next prev parent reply other threads:[~2006-05-17 18:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-17 17:25 send(), sendmsg(), sendto() not thread-safe Benjamin Reed
2006-05-17 18:00 ` Christopher Friesen [this message]
2006-05-17 18:21 ` Benjamin Reed
2006-05-17 18:52 ` Rick Jones
2006-05-17 19:06 ` Benjamin Reed
[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
[not found] <OFE8460E54.0C8D85D8-ON8525716F.0074F22F-8825716F.0076D537@us.ibm.com>
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
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=446B64D4.6080301@nortel.com \
--to=cfriesen@nortel.com \
--cc=br33d@yahoo.com \
--cc=netdev@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).