ahcox
ahcox

Reputation: 9970

Does C++ async use a thread pool when building for macOS with Xcode?

Using the standard development tools and compilers for the platform[1], does std::async spawn a new OS thread for each background job or does it use a thread pool or some system based on work stealing task queues?

  1. Xcode, Clang/LLVM

Upvotes: 5

Views: 716

Answers (2)

ahcox
ahcox

Reputation: 9970

An application built with the standard toolchain for the platform (Xcode/Clang) does not use a thread pool. The base of the stack of a task launched with std::async contains std::thread and pthread calls.

Stack trace showing async job running on a dedicated OS thread

On exit, each job calls pthread_exit() to kill the thread running it.

enter image description here

Xcode 8.3.3 also uses an OS thread per job launched with std::async when building for iOS (Tested on original iPad Pro 9.7" target).

enter image description here

Upvotes: 5

SergeyA
SergeyA

Reputation: 62603

No major standard implementation currently uses thread pools for std::async. Despite that notion that implementation could do this, this would be extremely hard in practice for implementations, and I do not foresee it in any near future.

Upvotes: 1

Related Questions