Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo
I use a Rexx script on a w2000 BOX witch look at each execution for parameters in a text files with the LINEIN fonction.
I need to execute several Rexx scripts at the same time. when this occur the first one run correctly but the other failed beacause they did'nt find the parameter text file witch is in use by the first script.
do you have any idea to unock the text file file read when the script use it
sorry or my poor english
Regina 3.3 Win32
I can think of several approaches.
Read in the entire file quickly storing lines in a stem variable, then close the file with STREAM() perhaps. This might still leave the file *briefly* inaccesible to the other REXX scripts. Along the same line of thought use RegStemRead() from REXXUTIL (McPhee).
You can try opening the file explicitly, and before any other operation, using STREAM(file, 'C', 'OPEN READ').
This may work for you, but you will need to test it there.
If one script always is started first one might read the file there and store the data in an external queue accessible to other processes. Exercise left to reader.
Scripts 2 ,3 ,4 ... could loop waiting for the data file to become available...
If NTx, then the OS TYPE command might be utilized in conjunction with ADDRESS WITH syntax to "read" the file and stuff the data (lines) into a stem var. TYPE will usually work when typical file locks are placed on the file.
There may be other ideas. Platform information is important. As may the actual Regina version used.
A solution in a different approach is to create 2 external functions. EXTERNAL_ENTER_CRITICAL and EXTERNAL_EXIT_CRITICAL.
implementation of EXTERNAL_ENTER_CRITICAL says if globalRexx variable=0, then increment and exit function. else wait for the globalRexx variable to be 0
implementation of EXTERNAL_EXIT_CRITICAL says if globalRexx variable>0, then decrement and exit function.
make sure to sync that global variable properly.
This makes sure that you can read the file and close it quickly without "maybe" crashing if 2 read it at the same time.
This is an approach that assumes that it is unsolvable reading the file without locking it and that REXX doesnt already have functions for this, neither which i checked.
Robert A "Bob" Cruz
Another possible solution is based on the fact that environment variables are NOT locked (they are copied to subordinate tasks). If the parm file is small, your first program could copy all the lines of the parm file into the environment, and the programs it starts could retrieve the parms from the environment variables.
To set an environment variable from REXX, code:
CALL VALUE 'env_var_name', env_val, 'ENVIRONMENT'
where <env_var_name> is the name of the environment variable you wish to set, as a string value. For example, to set the environment variable NUMBER_OF_LINES to 5, you would code:
CALL VALUE 'NUMBER_OF_LINES', 5, 'ENVIRONMENT'
Of course, all the parameters to VALUE() can be REXX variables or expressions.
To obtain the value of an environment variable, use VALUE as a function:
env_val = VALUE( 'env_var_name', , 'ENVIRONMENT' )
Note that the second parameter must be *omitted*.
Given this knowledge, the master program can read the parameter file for its own use, and place a copy of its contents into the environment with a loop like this:
parm_file_name = 'PARM.FIL' /*or whatever*/
DO ii = 1 BY 1 WHILE LINES( parm_file_name ) > 0
parm_line.ii = LINEIN( parm_file_name )
CALL VALUE 'PARM'ii, parm_line.ii, 'ENVIRONMENT'
/* the above sets PARM1, PARM2, PARM3, etc */
/* now record the number of lines in the parm file */
parm_line.0 = ii - 1
CALL VALUE 'PARM0', parm_line.0, 'ENVIRONMENT'
When each of the auxilliary programs is started by the master program, it will inherit a copy of the environment with all the parms in it. The auxilliary programs can read the parms in from the environment with this loop:
parm_line.0 = VALUE( 'PARM0', , 'ENVIRONMENT' )
DO ii = 1 TO parm_line.0
parm_line.ii = VALUE( 'PARM'ii, , 'ENVIRONMENT' )