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]

2.5.1: flock blocks when it shouldn't (NT-10.0, x86_64)


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
#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);
}
--
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

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