![]() |
install examples documentation |
|
lock-file <file path> id [ define ] <lock id> status [ define ] <status>
// Get application home directory
get-app directory to define dir
// Create lock file name
write-string define fname
@<<p-out dir>>/.lock
end-write-string
// Enter loop in which something is done, OR, program waits for others to complete their work before doing its own
num lockid;
while (1) {
// Attempt to lock file
lock-file fname id lockid status define lockst
// Check the status of locking
if (lockst == VV_OKAY) {
// File successfully locked, simulate working for 20 seconds
@WORKING
sleep (20);
@DONE
// Exit while loop
break;
} else if (lockst == VV_ERR_FAILED) {
// Another process holds the lock, wait, try again
sleep(1);
@WAITING
continue;
} else if (lockst == VV_ERR_OPEN || lockst == VV_ERR_INVALID) {
// Errors
@BAD LOCK
return;
}
}
// Once done, unlock file
unlock-file id lockid
return;