Main Content

ThreadPool

Parallel pool of thread workers on the local machine

Since R2020a

Description

Use parpool to create a parallel pool of thread workers on your local machine. After you create the pool, parallel pool features, such as parfor or parfeval, run on the workers. With the ThreadPool object, you can interact with the parallel pool.

Creation

Create a parallel pool of thread workers on the local machine by using the parpool function.

pool = parpool("threads")

Properties

expand all

This property is read-only.

Queue of FevalFuture objects to run on the thread pool, returned as a FevalQueue object. You can use this property to check the pending and running future variables of the parallel pool. To create future variables, use parfeval and parfevalOnAll. For more information on future variables, see Future.

Data Types: FevalQueue

This property is read-only.

Number of thread workers comprising the parallel pool, specified as an integer.

This property is read-only.

Flag that indicates whether the thread pool is busy, specified as true or false. The pool is busy if there is outstanding work for the pool to complete.

Object Functions

deleteShut down parallel pool
parfevalRun function on parallel pool worker
parfevalOnAllExecute function asynchronously on all workers in parallel pool

Limitations

  • Pools created using parpool('threads') and backgroundPool are both thread-based pools which utilize the same resources. It is possible that activity on one pool may block activity on the other and vice versa. Additionally, persistent data and random number generation stream state are shared in between these pools. For more information on controlling random number streams, see Control Random Number Streams on Workers.

Version History

Introduced in R2020a