Benoît Minisini schrieb: >> Sharing a file exclusively locked very briefly and getting everything >> to work correctly amongst multiple programs can be brain-twisting. >> With increasing use of mulit-cores, the possibility for sharing files >> using any lock technique is more important than ever before >> because all associated programs can execute simultaneously. >> > > You can use the LOCK/UNLOCK commands and a specific void file on the disk to > create system exclusive sections in your code. > > Let's suppose you want to modify a file named "/tmp/foo". > > ... > DIM hLock AS Stream > DIM hFile AS Stream > > ' Try to acquire the lock > TRY hLock = LOCK "/tmp/foo.lock" > IF ERROR THEN > PRINT "'foo' is being modified. Try again later." > RETURN > ENDIF > > ' Lock was acquired, you can modify the file now! > hFile = OPEN "/tmp/foo" FOR OUTPUT > ... > CLOSE #hFile > > ' Do not forget to release the lock > UNLOCK hLock > ... >
Just one question: Why do you use AS Stream and not AS File? Rolf ------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user