swirl Guide to OmniMark 6   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesOMX VariablesErrors
 
     
Locking a file

You can lock a file for such purposes as maintaining a hit counter on a website, by using OmniMark's omvfs library.

To lock a file for such a hit counter, create a program like this one:

    include "omvfs.xin"
    process
       local VFSFile counter-file
       local stream hit-count

       ; set up a vfsfile for the counter
       set counter-file to vfsOpen "counter.txt" for vfs-read-write

       vfsLock counter-file

       ; read and increment the hit-count
       set hit-count to "d" % vfsRead counter-file + 1

       ; output the hit-count
       output hit-count

       ; output the updated counter
       vfsMoveCursor counter-file to 0
       set vfsWrite counter-file to hit-count
       vfsUnlock counter-file

       ; a catch block for handling errors in this program
       catch #external-exception
        identity catch-id
        message catch-msg
          put #ERROR 'An error occurred while accessing a VFSFile'
          put #ERROR '%g(catch-id) : %g(catch-msg)%n'

This program does the following:

  1. Creates the the stream hit-count, and the vfsFile counter-file.
  2. Sets counter-file to the file named "counter.txt" by using vfsOpen.
  3. Uses the omvfs library function vfsLock to lock counter-file for the duration of this program.
  4. Increments hit-count by adding 1 to the contents of counter-file.
  5. Outputs hit-count.
  6. Sets counter-file to the value of hit-count using vfsWrite, thus updating the file "c:\counter.txt".
  7. At the end, unlocks counter-file with the omvfs library function vfsUnlock so another process can update it.

       
----

Top [ INDEX ] [ CONCEPTS ] [ TASKS ] [ SYNTAX ] [ LIBRARIES ] [ OMX ] [ ERRORS ]

OmniMark 6.5 Documentation Generated: December 23, 2002 at 6:24:54 pm
If you have any comments about this section of the documentation, send email to [email protected]

Copyright © OmniMark Technologies Corporation, 1988-2002.