<<

Contents

Search

>>

 

SYNCHRONIZED

 

 

Instruction

 

 

Syntax:

SYNCHRONIZED(<Object number>) … instructions … ENDSYNC

 

<Object number> = <NUM-EXPRESSION>

 

Meaning:

Under Java, those threads which are started by a timer or START_THREAD, run as seperate threads parallel to the current processing. Therefore, file accesses and accesses to shared variables must be synchronized.

 

Accesses are snychronized via objects. For this purpose, 32 objects (number 0 to 31) are available in the Ebus-J program.

 

If there are several threads trying to carry out instructions in the block SYNCHRONIZED ... ENDSYNC with the same object number, it is made sure that only one thread can carry out all instructions of the block by itself. Other threads wanting to carry out SYNCHRONIZED with the same <object number> must wait until the currently working thread has finished the instruction ENDSYNC.

 

<Object number> must lie between 0 and 31. If <Object number> <0 or >31, <Object number> 0 is used.

 

Note: The synchronization takes some computing time. If there are many blocks SYNCHRONIZED ... END (for example in FOR or WHILE loops) to be executed, it may be that more computing time is needed for two parallel threads than would be needed with a sequential execution. Therefore, you should use SYNCHRONIZED sparingly.

 

Parameter:

Object number

Number of synchronization object (0,…,31)

 

Sample:

DIM TABLE%(1000)

 

START_THREAD(PROG.COMPUTE)

 

Macro PROG.COMPUTE:

 

...

SYNCHRONIZED(1)

TABLE%(50) = COMPUTED_VALUE%

ENDSYNC

...

 

See also:

START_THREAD

ADD_SYNCHRONIZED

SET_SYNCHRONIZED

SYNCHRONIZE_MOUSE