1234567891011121314151617181920212223242526 |
- #include <stdio.h>
- int main(void) {
- FILE* f = fopen("stdio/stdio.in", "r");
- flockfile(f);
- // Commenting this out should cause a deadlock:
- // flockfile(f);
- if (!ftrylockfile(f)) {
- puts("Mutex unlocked but it shouldn't be");
- return -1;
- }
- funlockfile(f);
- if (ftrylockfile(f)) {
- puts("Mutex locked but it shouldn't be");
- return -1;
- }
- if (!ftrylockfile(f)) {
- puts("Mutex unlocked but it shouldn't be");
- return -1;
- }
- funlockfile(f);
- }
|