<<

Contents

Search

>>

 

SET_SYNCHRONIZED

 

 

Function

 

 

Syntax:

SET_SYNCHRONIZED(<Number of Variable>,<Old Value>,<New Value>)

 

<Number of Variable>

= <NUM-EXPRESSION>

<Old Value>

= <NUM-EXPRESSION>

<New Value>

= <NUM-EXPRESSION>

 

 

Meaning:

Synchronizes threads.

 

Under Java Macros that are started by a timer run as separate thread simultaneously to the current processing. File accesses and accesses to commonly used variables must therefore be synchronized.

 

With the functions SET_SYNCHRONIZED and ADD_SYNCHRONIZED 10 integer variables (<Number of Variable> = 0,...,9) are provided, by which threads can be synchronized. All variables are set to 0 at the start of the program.

 

The function SET_SYNCHRONIZED checks whether the variable <Number of Variable> has the value <Old Value>. If yes, the value of the variable is changed to <New Value> and the function returns the result 1. If the variable <Number of Variable> does not have the value <Old Value>, the value of the variable is not changed and SET_SYNCHRONIZED returns the result –1. 

 

If <Number of Variable> < 0 or > 9, SET_SYNCHRONIZED returns the result -2. 

 

<Number of Variable>, <Old Value> and <New Value> must contain integer values. 

 

SET_SYNCHRONIZED is 'thread safe'. This means that it is made sure that only one thread can access the variables and therefore the value of the variables is always well defined.

 

Parameter:

Number of Variable

Number of variable (0,...,9)

Old Value

Old value of the variable

New Value

New value of the variable

 

Sample:

ON TIMER MACRO MEETING.DATE

...

Macro MEETING.DATE:

/* check whether variable 2 can be changed from 0 to 1

IF SET_SYNCHRONIZED(2,0,1) = -1

THEN /* Another thread has set the variable to 1 and is still busy

     /* ... display error message or wait and try again ...

ELSE ... Read date from file MEETINGS ...

     /* Reset variable to 0

     IF SET_SYNCHRONIZED(2,1,0) = -1

     THEN /* This must be a bug, because another program has changed

          /* the value of the variable

     ENDIF

ENDIF

 

See also:

ADD_SYNCHRONIZED

SYNCHRONIZED

START_THREAD