• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Product
    • Design UI
    • Develop
    • Analyze and test
    • Deploy
    • Framework and toolbox
    • Compatibility
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • Framework - CDP Core
  • OSAPISemaphore
  • 4.11.14

OSAPISemaphore Class

The OSAPISemaphore is a counting semaphore for synchronisation. More...

Header: #include <OSAPI/Process/OSAPISemaphore.h>
  • List of all members, including inherited members

Public Functions

OSAPISemaphore(int initialCount = SEMAPHORE_INITIAL_COUNT)
virtual ~OSAPISemaphore()
void Destroy()
int Lock()
void Release()
void Release(int count)
int TryLock()

Detailed Description

The OSAPISemaphore is a counting semaphore for synchronisation.

Default created with inital count == 1 (i.e. signaled, or non-blocked, state). This makes the semaphore behave exactly like a mutex (binary semaphore).

Locking a binary semaphore twice will suspend the execution of the calling thread until some other thread releases the semaphore. Note that locked semaphores do not have to be released by the same thread that locked it. This is not allowed by mutexes.

The semaphore can be used to limit access to resources, but in contrast to mutexes it can allow multiple threads access at the same time. This is done by setting initialCount during construction (e.g. OSAPISemaphore sem(2); allows two threads to lock the semaphore simultaneously).

See also OSAPIMutex and OSAPIMutexLocker.

Member Function Documentation

OSAPISemaphore::OSAPISemaphore(int initialCount = SEMAPHORE_INITIAL_COUNT)

Constructs a semaphore.

[virtual] OSAPISemaphore::~OSAPISemaphore()

Destructs the semaphore.

void OSAPISemaphore::Destroy()

Destroys the semaphore by releasing all allocated resources.

If semaphore is created, it will be destroyed. This means no thread may be waiting for the semaphore when calling Destroy().

int OSAPISemaphore::Lock()

Locks the semaphore by decreasing lock count.

If already locked the calling process or thread will be suspended until Semaphore is signaled.

Returns 1 if semaphore successfully locked.

void OSAPISemaphore::Release()

Signals and releases the semaphore by increasing lock count by 1.

void OSAPISemaphore::Release(int count)

Signals and releases the semaphore by increasing lock count.

Parameter countNumber of counts to increase.

int OSAPISemaphore::TryLock()

Tries to lock the semaphore.

Locks if not blocked. Does not wait if blocked. Returns 1 if semaphore successfully locked.

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

    © Copyright 2022 CDP Technologies. Privacy and cookie policy.

    Return to top