www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/09/20/04:10:22

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Thu, 20 Sep 2007 10:09:54 +0200
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: file locking problem
Message-ID: <20070920080954.GF22259@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <fcsbji$bj0$1 AT sea DOT gmane DOT org>
Mime-Version: 1.0
In-Reply-To: <fcsbji$bj0$1@sea.gmane.org>
User-Agent: Mutt/1.4.2.2i
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Sep 19 19:30, BJ wrote:
> I have a file locking problem that is solved under Mac and Linux using
> fcntl:
> int lockRepFile (int fd, char lock, size_t from, size_t length) {
> struct flock fl;
> 
>       fl.l_start = from;
>       fl.l_len = length;
>       fl.l_pid = 0;
> 
>       if (lock == 'r') fl.l_type = F_RDLCK;
>       else if (lock == 'w')  fl.l_type = F_WRLCK;
>       else if (lock == 'u')  fl.l_type = F_UNLCK;
>       fl.l_whence = SEEK_SET;
> 
>       return (fcntl(fd, F_SETLKW, &fl));
> }
> 
> Now, unfortunately this hangs occasionally using cygwin - gcc.
> 
> I would appreciate any comments and suggestions on how debug this and how to
> improve the performance i.e. stop it from hanging...

F_SETLKW is supposed to hang if the lock is held by another application.
Use F_SETLK instead.

Apart from that, Cygwin has a problem in that Windows doesn't support
advisory locks as are default on Linux and BSD.  Windows only supports
mandatory locking.  So far Cygwin's fcntl uses Window's mandatory
locking, it doesn't implement its own advisory locking.  Maybe that's
your problem.

If none of the above helps, maybe a more detailed problem report with a
reproducible testcase might be the way to go.  See
http://cygwin.com/problems.html


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019