PDA

View Full Version : Global Macros that refresh


Too_Tall_Crown_Victoria
09-02-2010, 11:40 AM
We have a need to create a global counter for how many times a task runs. We have approximately 10 build scripts that can each run around the same time. My first iteration was to create a global subroutine that will increment a global macro. However, I discovered that the global macros are not being updated as each script runs. It seems that the global macro states are read when the script starts and remains with the script. So if one script updates a macro, that update is not seen by the other scripts running.

Is there a way to make this happen so that these macros are up to date so I can use these global macros as counters for all scripts running? If this will not work, do you have another suggestion as to how to make this work and avoid collisions?

Thanks

kinook
09-02-2010, 01:06 PM
Global macro changes made by other instances of Visual Build are reloaded before each step.
http://www.kinook.com/VisBuildPro/Manual/globalmacros.htm

However, this is not an atomic/interlocked update, so near-simultaneous changes made by one instance could overwrite those of another (both could read value x, increment to x+1 and save instead of ending up at x+2), and file in use errors could occur with several simultaneous instances all updating global macros at once.

To implement a true atomic update, one way might be to call a program that opens a common file for exclusive access (waiting+retrying if already in use), then reads+updates the value in the file, and closes the file and returns the value. I don't believe this can be done with the scripting FileSystemObject and may require something like C# or C.