This is the mail archive of the
cygwin
mailing list for the Cygwin project.
2.5.1: flock blocks when it shouldn't (NT-10.0, x86_64)
- From: RG <zx dot devel at gmail dot com>
- To: cygwin at cygwin dot com
- Date: Tue, 21 Jun 2016 06:04:12 +0100
- Subject: 2.5.1: flock blocks when it shouldn't (NT-10.0, x86_64)
- Authentication-results: sourceware.org; auth=none
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