#!/usr/local/bin/rune -x # import "sys"; import ; int main(int ac, char **av) { Fs fs; size_t off; if (ac == 1) { stdio.stdout->format("Supply filename for flock test\n"); Sys.exit(1); } if (fs.open(av[1], O_RDWR) < 0) { stdio.stdout->format("open(%s) failed error %d\n", av[1], fs.error); } else if (fs.flock(LOCK_EX | LOCK_NB) < 0) { stdio.stdout->format("flock() failed error %d\n", fs.error); } else { stdio.stdout->format("flock() suceeded error %d\n", fs.error); stdio.stdout->format("sleeping for 2 seconds\n"); Thread.mssleep(2000); if (fs.flock(LOCK_UN) < 0) stdio.stdout->format("flock(LOCK_UN) " "failed error %d\n", fs.error); } # Should obtain lock on each loop and destructor should # release it on each loop. # for (off = 0; off < 1024Z; off += 32Z) { FdLock fl; fl.start = off; fl.len = 32; fl.type = fl.F_WRLCK; fl.fd = fs.fd; stdio.stdout->format("lock %d\n", off); fl.fsetlkw(); stdio.stdout->format("result %d --> %d type=%d\n", off, fl.error, fl.type); Thread.mssleep(2000); stdio.stdout->format("unlock %d\n", off); } }