/* ** Program ExLock.ox ** ** Purpose: ** Provide an example of the usage of lockfile.ox ** ** Author: ** Charles Bos ** ** Date: ** 29/4/2002 */ #include #include lengthycalculation(const iN, const sFilebase) { decl j, mX, mY; println("Running computation for ", sFilebase, ".fmt"); mX= rann(10, 10); for (j= 0; j < iN; ++j) mY= exp(mX); // Save the results savemat(sFilebase~".fmt", mY); } main() { decl iN, mX, sFile; iN= 1000; sFile= "output/res"; println("Do some calculations, resulting in output ", sFile, ".fmt"); if (lockfile(sFile)) mX= lengthycalculation(iN, sFile); else println ("Couldn't do the first iteration of the computation"); println("Second try will not succeed, as file res1 is still locked"); if (lockfile(sFile)) mX= lengthycalculation(iN, sFile); else println ("Couldn't do the second try of the computation"); println("Unlocking res1..."); unlockfile(sFile); println("Third try works again, as file res1 is now unlocked"); if (lockfile(sFile)) mX= lengthycalculation(iN, sFile); else println ("Couldn't do the third try of the computation"); println("Unlocking ", sFile, "..."); unlockfile(sFile); }