Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Killer Application

From: atruter:hih:au at: 19-Aug-2002 10:19

<snip>
Rebol [ Name: 'Number Title: "Title" File: %Number.r Author: "Andrew Martin" eMail: [Al--Bri--xtra--co--nz] Date: 17/Aug/2002 ] Number: has [File Number] [ File: %Number.txt if not exists? File [ save File 0 ] Number: load File Number: Number + 1 save File Number Number ] </snip> To prevent more than one session obtaining the same number (assuming the file is stored on shared media) some form of locking may be required. The following code could serve as the basis for such: <code> lock-index: function [path] [lock?] [ lock?: false repeat cnt 5 [ either none? attempt [rename join path %index.dat %lock.dat] [ wait 1 print reform ["Waited:" cnt] ][ lock?: true break ] ] if not lock? [print reform ["Could not lock" join path %index.dat]] ] ; ... code that reads / writes path/lock.dat unlock-index: func [path] [ if none? attempt [rename join path %lock.dat %index.dat] [ print reform ["Could not unlock" join path %lock.dat] ] ] </code> Regards, Ashley