public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* 2.5.1: flock blocks when it shouldn't (NT-10.0, x86_64)
@ 2016-06-21  9:04 RG
  2016-06-21 14:03 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: RG @ 2016-06-21  9:04 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 206 bytes --]

Hello,

I have encountered unexpected behavior when using flock.
It will block forever, but to my understanding it should not.
I've attached a simple program that would trigger the behavior.

Regards,
Alex

[-- Attachment #2: flock_hang.c --]
[-- Type: text/x-csrc, Size: 553 bytes --]

#include <stdio.h>
#include <unistd.h>
#include <sys/file.h>

FILE *fp;

void main() {
    unlink("a"); unlink("b");

    fp = fopen("a", "wb"); // file a

    printf("lock a\n");
    flock(fileno(fp), LOCK_EX);

    fwrite("TEST", sizeof(char), 4, fp);

    printf("unlock a\n");
    flock(fileno(fp), LOCK_UN);
    fclose(fp);

    fp = fopen("b", "wb");  // file b

    printf("lock b\n");
    flock(fileno(fp), LOCK_EX);  // hang

    fwrite("TEST", sizeof(char), 4, fp);

    printf("unlock b\n");
    flock(fileno(fp), LOCK_UN);
    fclose(fp);
}

[-- Attachment #3: Type: text/plain, Size: 218 bytes --]

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-06-21 12:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-21  9:04 2.5.1: flock blocks when it shouldn't (NT-10.0, x86_64) RG
2016-06-21 14:03 ` Corinna Vinschen

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 read-only IMAP folder(s) and NNTP newsgroup(s).