A critical section is a section of code that accesses a shared resource, where this resource must not be accessed at the same time as another thread. For example, only one thread at a time should write to a log file. If multiple threads write to a log file at the same time, the resulting text in the file could be an unpredictable mix up of text from each thread.
It is important to implement critical section locks when using either the Java or the C++ SDKs. If you are using the Java SDK, you can use standard Java classes to handle locking. If you are using the C++ SDK, you can use the classes provided by the SimbaEngine X SDK.
A critical sections of code should be specific using a
CriticalSection object. A
CriticalSectionLock object can then be used to lock this critical section to prevent concurrent access by another thread.
Your implementation of
GetDriverLog, for example
CustomerDSIIDriver::GetDriverLog, should use a
To use critical sections and critical section locks:
CriticalSectionmember variable. For example:
CriticalSectionLockto lock the critical section. Add the following line of code to the start of the function:
The lock will be released once the function returns.
For more information on the
CriticalSectionLock classes, see the SimbaEngine C++ API Reference.