CHECKOUT_LOCK_FILETrytoestablishcontrolofalockfile[FID,KEY]=vlt.file.checkout_lock_file(FILENAME)ThisfunctiontriestocheckoutthefileFILENAMEsothatdifferentprogramsdonotperformsomeoperationatthesametime.Thisisaquickanddirtysemaphoreimplementation(seeWikipediaifunfamilarwithsemaphores).TheLOCKFILEwillalsoEXPIREin1hourunlessotherwisespecifiedbelow.AKEYisreturned,whichisnecessarytopasstotovlt.file.release_lock_file.ThisfunctiontriestocreateanemptyfilecalledFILENAME.IfthefileisNOTalreadypresentandthecreationsuccessful,thefilewillbecreatedandFIDwillreturnthefileID(seehelpfopen).Ifinsteadthefilealreadyexists,thefunctionwillcheckevery1secondfor30iterationstoseeifthefiledisappears.Ifthefunctionisneverabletocreateanewfilebecausetheoldfileexists,thenthefunctionwillgiveupandreturnFID<0.IMPORTANT:RESPONSIBLECLEANUP:Itisimportantthatiftheprogramthatcallsvlt.file.checkout_lock_fileisabletocreatethefile(thatis,FID>0),thenitshouldcallvlt.file.release_lock_filetoremovethelockfile.IMPORANT:FILECLOSURE:If2outputargumentsaregiven(thatis,KEYisexamined),thenthelockfileisclosedbeforevlt.file.checkout_lock_fileexits.IfKEYisnotrequestedinoutput,thentheFIDisleftopenforbackwardscompatibility.Depricatedreleaseinstructions(newcodeshouldnotuse):1)closethefilewithfclose(FID)and2)deletethefileFILENAMEthatiscreatedwithdelete(FILENAME).IfFID<0,thenitshouldNOTdeletethefileFILENAMEbecauseitischeckedoutbysomeotherprogram.Thefunctioncanbecalledwithadditionaloutputarguments:[FID,KEY]=vlt.file.checkout_lock_file(FILENAME,CHECKLOOPS)Altersthenumberoftimesthefunctionwillcheck(at1secondintervals)toseeifFILENAMEhasdisappeared.[FID,KEY]=vlt.file.checkout_lock_file(FILENAME,CHECKLOOPS,THROWERROR)IfTHROWERRORis1,thefunctionwillreturnanerrorinsteadofreturningFID<0.[FID,KEY]=vlt.file.checkout_lock_file(FILENAME,CHECKLOOPS,THROWERROR,EXPIRATION_SECONDS)Thismodeallowsonetospecificallysettheexpirationtimeinseconds.vlt.file.checkout_lock_filewillexaminethefilefortheexpirationtimeandignoreandremovethelockfileifitis"expired".Bydefault,EXPIRATION_SECONDSis3600.Example:% I want to make sure only my program writes to myfile.txt.% All of my programs that write to myfile.txt will "check out" the % file by creating myfile.txt-lock.mylockfile=[userpathfilesep'myfile.txt-lock'];[lockfid,key]=vlt.file.checkout_lock_file(mylockfile);iflockfid>0,% do somethingvlt.file.release_lock_file(mylockfile,key);else,error(['Never got control of 'mylockfile'; it was busy.']);end;Seealso:vlt.file.release_lock_file,FOPEN,DELETE