We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 28c5dfe commit 93b127dCopy full SHA for 93b127d
multithreading/02 - Flock.c
@@ -25,7 +25,12 @@ int lock_write()
25
return 0;
26
}
27
28
- flock(fd, LOCK_EX | LOCK_NB);
+ if (flock(fd, LOCK_EX | LOCK_NB) < 0)
29
+ {
30
+ printf("Access to LOCK error.\n");
31
+ close(fd);
32
+ return 0;
33
+ }
34
35
const char buf[] = "ABRACADABRA";
36
write(fd, &buf, strlen(buf) + 1);
@@ -47,7 +52,12 @@ int lock_read(pid_t pid)
47
52
48
53
49
54
50
- flock(fd, LOCK_SH | LOCK_NB);
55
+ if (flock(fd, LOCK_SH | LOCK_NB) < 0)
56
57
58
59
60
51
61
62
char buf[12];
63
read(fd, &buf, 12);
0 commit comments