linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "David Schwartz" <davids@webmaster.com>
To: "Mikhail Kruk" <meshko@cs.brandeis.edu>,
	"Jamie Lokier" <jamie@shareable.org>
Cc: <linux-kernel@vger.kernel.org>
Subject: RE: fcntl file locking and pthreads
Date: Sun, 4 May 2003 11:40:50 -0700	[thread overview]
Message-ID: <MDEHLPKNGKAHNMBLJOLKKEHKCLAA.davids@webmaster.com> (raw)
In-Reply-To: <Pine.LNX.4.33.0305040922020.32427-100000@iole.cs.brandeis.edu>


> CLONE_FILES is an argument to clone(), I'm using pthreads and I don't
> know if LinuxThreads implementation of pthreads gives me control of
> how clone is called. Anyway, if I understand what CLONE_FILES does,
> it should be given to clone, because threads do have to be able
> to share file
> descriptors, probably. But not the locks!

	What if I have an application where requests are written to files. Thread A
comes along and notices a job in a file, so it locks the file and reads the
job. The job will require some network I/O, so the thread goes on to do
other things. Later on, thread B notices the network I/O has completed, so
it needs to write to the file, release the lock, and close the file.

	Making locks local to specific threads is contrary to the whole purpose of
threads. Work that needs to be done on a file descriptor is supposed to be
doable by any thread.

	This is something that can be solved with application code. Just keep a
table of all your file locks and consult the table before attempting to
acquire a lock from the system. This is no different than the housekeeping
required around 'malloc' (or more accurately 'sbrk').

	DS



  parent reply	other threads:[~2003-05-04 18:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-04  6:13 fcntl file locking and pthreads Mikhail Kruk
2003-05-04 12:58 ` Jamie Lokier
2003-05-04 13:25   ` Mikhail Kruk
2003-05-04 15:24     ` Miquel van Smoorenburg
2003-05-04 18:40     ` David Schwartz [this message]
2003-05-04 19:29       ` Mikhail Kruk
2003-05-04 20:55         ` David Schwartz
2003-05-04 21:50           ` Mikhail Kruk
2003-05-04 21:29 ` Mark Mielke
2003-05-04 21:56 Ville Voutilainen
2003-05-04 22:04 ` Mikhail Kruk
2003-05-04 22:29 Ville Voutilainen

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=MDEHLPKNGKAHNMBLJOLKKEHKCLAA.davids@webmaster.com \
    --to=davids@webmaster.com \
    --cc=jamie@shareable.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=meshko@cs.brandeis.edu \
    /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).