Figure 2 Example of a RAM Semaphore to Protect a Static Variable

#include <os2.h>

SHORT GetUpdateAppCounter(SHORT sUpdCnt)
{
    auto     USHORT       usRC;
    auto     SHORT        sInstCnt;
    static   SHORT        sCounter  = 0;
    static   ULONG        ulSem     = 0L;

    usRC = DosSemRequest(&ulSem, SEM_INDEFINATE_WAIT);
    if (usRC)
        ErrorMsg("GetUpdateAppCounter", usRC);  // return
    sCounter += sUpdCnt;
    sInstCnt  = sCounter;

    DosSemClear(&ulSem);
    return(sInstCnt);
}