• 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
  • Products
    • Automation Designer
    • HMI Designer
    • Maritime HMIs
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • Framework - CDP Core
  • CDPThreadPool
  • 5.0.0

CDPThreadPool Class

The CDPThreadPool class is used to manage a pool of threads for executing tasks concurrently. More...

Header: #include <CDPThreadPool>
  • List of all members, including inherited members

Public Functions

CDPThreadPool(std::size_t numThreads, std::size_t threadStackSize = 64 * 1024, CDP::ThreadPriority priority = CDP::LowThreadPriority, const std::string &threadBaseName = "CTPool")
~CDPThreadPool()
void Await(double seconds)
std::size_t GetThreadCount()
CDP::ThreadPriority GetThreadPriority()
std::size_t GetThreadStackSize()
bool IsStopped()
void Join()
void Post(std::function<void() > task)
void Stop()

Detailed Description

The CDPThreadPool class is used to manage a pool of threads for executing tasks concurrently.

Usage

  • Instantiate an object of CDPThreadPool, specifying the number of threads, stack size per thread, thread priority, and a base name for threads.
  • Use the Post() method to submit tasks to be executed by the thread pool.
  • The Join(), Stop(), and Await() methods are available to synchronize with the execution of tasks.
CDPThreadPool pool(4);  // Creates a pool with 4 threads
pool.Post([](){ std::cout << "Task 1" << std::endl; });
pool.Post([](){ std::cout << "Task 2" << std::endl; });
pool.Join();  // Wait for all tasks to complete

See also CDP::ThreadPriority.

Member Function Documentation

CDPThreadPool::CDPThreadPool(std::size_t numThreads, std::size_t threadStackSize = 64 * 1024, CDP::ThreadPriority priority = CDP::LowThreadPriority, const std::string &threadBaseName = "CTPool")

Constructs a CDPThreadPool object with the specified number of threads, thread stack size, thread priority, and thread base name.

numThreads The number of threads in the pool. threadStackSize The stack size for each thread. priority The priority of threads. threadBaseName The base name for threads.

CDPThreadPool::~CDPThreadPool()

Destroys the CDPThreadPool object and ensures all threads have completed execution.

void CDPThreadPool::Await(double seconds)

Blocks the calling thread for the specified number of seconds or until all tasks have completed execution, whichever comes first.

seconds The number of seconds to wait.

std::size_t CDPThreadPool::GetThreadCount()

Returns the number of threads in the thread pool.

Returns the number of threads.

CDP::ThreadPriority CDPThreadPool::GetThreadPriority()

Returns the priority of threads in the thread pool.

Returns the thread priority.

std::size_t CDPThreadPool::GetThreadStackSize()

Returns the stack size of threads in the thread pool.

Returns the stack size.

bool CDPThreadPool::IsStopped()

Returns whether the thread pool has been stopped.

Returns true if the thread pool has been stopped; otherwise false.

void CDPThreadPool::Join()

Blocks the calling thread until all tasks have completed execution.

void CDPThreadPool::Post(std::function<void() > task)

Submits a task for execution by the thread pool.

task A function object representing the task to be executed.

void CDPThreadPool::Stop()

Stops the thread pool from executing any more tasks.

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 2025 CDP Technologies. Privacy and cookie policy.

Return to top