Files
RedBear-OS/tests/stdio/mutex.c
T
2018-10-15 15:24:14 +02:00

27 lines
526 B
C

#include <stdio.h>
int main() {
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);
}