• 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

  • Doc
  • 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
  • OSAPIThread
  • 4.12.9

OSAPIThread Class

The OSAPIThread is used to run code in a new thread. More...

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

Public Functions

virtual ~OSAPIThread()
virtual void Start(CDP::ThreadPriority priority, const char *name, int stackSize = 0)
  • 14 public functions inherited from OSAPITask

Protected Functions

virtual void Main() = 0

Detailed Description

The OSAPIThread is used to run code in a new thread.

Usage

  • To create a thread, make a subclass of OSAPIThread and implement the virtual void Main() function in the subclass.
  • To start the thread, call the Start() function.
  • To stop the thread, call Stop() function.
  • To free all resources allocated for the thread, call Delete() function.

Typical usage in a Component is to override the CDPComponent::Activate() and call OSAPIThread::Start() from there:

void MyComponent::Activate()
{
  CDPComponent::Activate(); // call base
  Start(CDPTHREAD_PRIORITY_HIGH,ShortName());
}

Also override CDPComponent::Suspend():

void MyComponent::Suspend()
{
  CDPComponent::Suspend();
  Stop();
  // trigger any blocking objects here, f.i. call Set() on OSAPIEvent to release a Wait().
  Delete(); // delete will block until thread is no longer running (for max. 2 seconds)
}

A typical Main() function:

void MyComponent::Main()
{
  while(!Stopped())
  {
    m_event.Wait();
    m_event.Reset();
    if(!Stopped())
      DoBlockingOperation();
  }
}

See also OSAPITask and CDPComponent.

Member Function Documentation

[virtual] OSAPIThread::~OSAPIThread()

Stops the running thread.

[pure virtual protected] void OSAPIThread::Main()

This Main() function will be called by the new thread when it has been created by Start().

Override this in your subclass and put your thread code in it. Your implementation of Main() should return if Stopped() returns true.

[virtual] void OSAPIThread::Start(CDP::ThreadPriority priority, const char *name, int stackSize = 0)

Start thread execution.

Parameter priorityThread priority level.

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

My account

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

© Copyright 2024 CDP Technologies. Privacy and cookie policy.

Return to top