Critical Sections

Given the event-triggered nature of statement execution in VTScada, there are times when you will need to ensure that certain tasks are completed before others execute. The CriticalSection() function is provided to achieve this.

A critical section is one whose execution cannot be interrupted by other threads. After being started, it is guaranteed to finish, assuming that your code is correctly written and able finish. When used, critical sections are typically placed in initialization states or in module constructors or destructors. For example:

If 1 Main;
[
  IfThen(Valid(level), 
        CriticalSection(temp = a, 
                         a = b, 
                         b = temp ) ); 
]

Any number of statements can be passed as parameters to the CriticalSection. Note that, being parameters, these are separated by commas rather than semicolons.

Do not over-use critical sections. Use only when certain processes absolutely must be started or values obtained before continuing.