This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: file locking problem

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


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

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]