Documentation for Axxon PSIM 1.0.0-1.0.1.

Previous page The CreateMsg method  The IsAvailableObject method Next page


The Lock and Unlock methods are used to create a global critical section when synchronization of scripts started in different streams is required. The Lock method opens a critical section and the Unlock method closes it.

Attention!

If you invoke the Lock method, you must also invoke the Unlock method. Otherwise, the system can freeze.

We recommend avoid using the Lock and Unlock methods.

Syntax for method invocation:

 function Lock()
 function Unlock()

Example. On macro 1, calculate the total amount of alarmed relays and sensors. Objects of each type must be calculated at the same time (in an individual script). The result must be written to the counter global variable.

Script 1:

 // Number of alarmed relays is calculated
var i = Number(0);
if (Event.SourceType == "MACRO" && Event.SourceId== "1" && Event.Action == "RUN")
{
var msg = CreateMsg();
msg.StringToMsg(GetObjectIds("GRELE"));
var objCount = msg.GetParam("id.count");
var k;
for(k= 0; k < objCount; k++)
if(GetObjectState("GRELE", msg.GetParam("id." + k))== "ALARM"){
    Lock();
     i = Itv_var("counter");
i++;
Itv_var("counter")=i;
Unlock();
}
}

Script 2:

 //Number of alarmed sensors is calculated
var i = Number(0);
 if (Event.SourceType == "MACRO" && Event.SourceId== "1" && Event.Action == "RUN")
{
var msg = CreateMsg();
msg.StringToMsg(GetObjectIds("GRAY"));
var objCount = msg.GetParam("id.count");
var k;
for(k = 0; k < objCount; k++)
if(GetObjectState("GRAY", msg.GetParam("id." + k))== "ALARMED"){
    Lock();
     i = Itv_var("counter");
i++;
Itv_var("counter")=i;
Unlock();
}
}

Note

If the Lock() and Unlock() methods are not used in this example, then collisions can occur and the calculated value will be less than the actual value.