From: David Schwartz <davids@webmaster.com>
To: <ifilipau@sussdd.de>,
"'linux-kernel@vger.kernel.org'" <linux-kernel@vger.kernel.org>
Subject: Re: read() & close()
Date: Fri, 21 Mar 2003 04:35:50 -0800 [thread overview]
Message-ID: <20030321122452Z263606-25575+33907@vger.kernel.org> (raw)
In-Reply-To: <7A5D4FEED80CD61192F2001083FC1CF9065139@CHARLY>
On Thu, 20 Mar 2003 15:14:52 +0100, Filipau, Ihar wrote:
>I have/had a simple issue with multi-threaded programs:
>
>one thread is doing blocking read(fd) or poll({fd}) on
>file/socket.
>
>another thread is doing close(fd).
>
>I expected first thread will unblock with some kind
>of error - but nope! It is blocked!
>
>Is it expected behaviour?
It is impossible to make this work reliably, so *please* don't do
that. For example, how can you possibly assure that the first thread
is actually in 'poll' when call 'close'? There is no atomic 'release
mutex and poll' function.
So what happens if the system pre-empts the thread right before it
calls 'poll'. Then you call 'close'. Perhaps next a thread started by
some library function calls 'socket' and gets the file descriptor you
just 'close'd. Now your call to 'poll' polls on the *wrong* socket!
You simply must accept the fact that you cannot free a resource in
one thread while another thread is or might be using it.
DS
next prev parent reply other threads:[~2003-03-21 12:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-03-20 14:14 Filipau, Ihar
2003-03-20 15:08 ` bert hubert
2003-03-21 12:35 ` David Schwartz [this message]
2003-03-20 16:09 Kevin Curtis
2003-03-21 8:07 Filipau, Ihar
2003-03-21 13:07 Filipau, Ihar
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=20030321122452Z263606-25575+33907@vger.kernel.org \
--to=davids@webmaster.com \
--cc=ifilipau@sussdd.de \
--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 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®