linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ville Voutilainen <vjv@ee.oulu.fi>
To: meshko@cs.brandeis.edu
Cc: linux-kernel@vger.kernel.org
Subject: Re: fcntl file locking and pthreads
Date: Mon, 5 May 2003 01:29:58 +0300 (EEST)	[thread overview]
Message-ID: <200305042229.h44MTwTf012142@stekt2.oulu.fi> (raw)

> actually what I have is:
> thread 0:
> pthread_create() (1)
> pthread_create() (2)
> thread 1:
> open()
> fcntl()
> thread 2:
> open()
> fcntl()
> and they all succeed. Even though the file descriptors are different. 

Which shows us that fcntl cannot detect a file lock held by
the current process, no matter how many times we open the same
file in order to get different file descriptors. Bloody POSIX,
might I say. :) I wonder if POSIX even says anything non-vague
wrt. to this. As in, if Linux would enable detecting
two locks on two different fds (pointing to the same file)
within one process, would Linux violate POSIX? Moreover, is
this simply so that kernel detects the situation just fine,
but the info is not carried to user space because good ole
fcntl behaviour doesn't really take threads into account?
In the marvellous scheme of things (user app -> glibc -> kernel
and back), at what point (if any) is it possible to detect
multiple locks within one process? And can it be done so that
fcntl can still be claimed to be even remotely compatible
with anything on the planet?

> You digress, but I feel like I have to justify myself now :)
> Those threads used to be processes and now want be threads with minimal 
> modifications. The files that are locked are still used by other processes 
> too.

Then, logically (I suppose you already know this, but..) you
need both the file locks and mutexes to sync with both other
threads and other processes. There, one more example of how
going multi-threaded sometimes adds (mostly locking) code.

I'll shut up now, we are only at the borderline of kernel-land
and if we aim for portability, we are probably solely and
firmly on the user-land side of the big picture.

-VJV-

             reply	other threads:[~2003-05-04 22:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-04 22:29 Ville Voutilainen [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-05-04 21:56 fcntl file locking and pthreads Ville Voutilainen
2003-05-04 22:04 ` Mikhail Kruk
2003-05-04  6:13 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
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

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=200305042229.h44MTwTf012142@stekt2.oulu.fi \
    --to=vjv@ee.oulu.fi \
    --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).