Simba Technologies
Simba Technologies

SimbaEngine X SDK 10.1.3
Developing Drivers for Data Stores Without SQL

Critical Section Locks

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.

Critical Section Locks in the C++ 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 CriticalSectionLock.

To use critical sections and critical section locks:

  1. Include the following files:

    #include “CriticalSection.h”

    #include “CriticalSectionLock.h”

  2. Define a CriticalSection member variable. For example:

    Simba::Support::CriticalSection m_criticalSection;

  3. For functions that use shared resources, use a CriticalSectionLock to lock the critical section. Add the following line of code to the start of the function:

    CriticalSectionLock lock(&m_criticalSection);

    The lock will be released once the function returns.

For more information on the CriticalSection and CriticalSectionLock classes, see the SimbaEngine C++ API Reference.