Storing cgi data in stacks

Brian Yennie briany at qldlearning.com
Wed Feb 18 14:32:52 EST 2004


I can't speak for MetaCard's behavior here, although my hope would be 
that it gives you an error message when you try to perform the second 
write.

However, what you are generally referring to would be acquiring a write 
lock on the stack, which is something you can manage yourself. It's 
mostly as simple as it would seem- you just need to be able to 
communicate some sort of global flag that you scripts can check.

For example:

## check if another script has a write lock
put isLocked() into someFlag
put the seconds into startTime

repeat until (someFlag is FALSE) or (timeElapsed > 10)
    ## wait until it's available
    put isLocked() into someFlag
    put the seconds - startTime into timeElapsed
end repeat

if (someFlag is TRUE) then
    put "Error: scripts too busy, couldn't write for 10 seconds!"
else
    lockStack
    writeToStack
    unlockStack
end if

You could implement the lock/unlock through an external file, say:

function isLocked
   return (there is a file "mc.lock")
end isLocked

on lockStack
    put empty into url "file:mc.lock"
end lockStack

on unlockStack
    delete file "mc.lock"
end unlockStack

There are more efficient ways to do locking, but this seems appropriate 
here.

HTH,
Brian

> And, more importantly, what steps could be taken in a cgi script to 
> make
> this approach work, if any?  Like, if a stack was currently being 
> written
> to, would darwin mc know that?  Is there some message returned like 
> "stack
> is in use" or something that you could trap for?  And maybe make your 
> own
> timeout?



More information about the metacard mailing list