Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/thread/launch"

From cppreference.com
< cpp‎ | thread
(Added LWG issue #2102 DR.)
m (~ fmt)
 
Line 11: Line 11:
 
{{tt|std::launch}} is a {{named req|BitmaskType}}. It specifies the launch policy for a task executed by the {{lc|std::async}} function.
 
{{tt|std::launch}} is a {{named req|BitmaskType}}. It specifies the launch policy for a task executed by the {{lc|std::async}} function.
  
 +
===Constants===
 
The following constants denoting individual bits are defined by the standard library:
 
The following constants denoting individual bits are defined by the standard library:
  
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc hitem|Constant|Explanation}}
+
{{dsc hitem|Name|Explanation}}
{{dsc|{{tt|std::launch::async}}|the task is executed on a different thread, potentially by creating and launching it first}}
+
{{dsc|{{tt|async}}|the task is executed on a different thread, potentially by creating and launching it first}}
{{dsc|{{tt|std::launch::deferred}}|the task is executed on the calling thread the first time its result is requested (lazy evaluation)}}
+
{{dsc|{{tt|deferred}}|the task is executed on the calling thread the first time its result is requested (lazy evaluation)}}
 
{{dsc end}}
 
{{dsc end}}
  

Latest revision as of 07:27, 9 July 2024

 
 
Concurrency support library
Threads
(C++11)
(C++20)
this_thread namespace
(C++11)
(C++11)
(C++11)
Cooperative cancellation
Mutual exclusion
(C++11)
Generic lock management
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
launch
(C++11)
Safe Reclamation
(C++26)
Hazard Pointers
Atomic types
(C++11)
(C++20)
Initialization of atomic types
(C++11)(deprecated in C++20)
(C++11)(deprecated in C++20)
Memory ordering
Free functions for atomic operations
Free functions for atomic flags
 
Defined in header <future>
enum class launch : /* unspecified */ {

    async =    /* unspecified */,
    deferred = /* unspecified */,
    /* implementation-defined */

};
(since C++11)

std::launch is a BitmaskType. It specifies the launch policy for a task executed by the std::async function.

[edit] Constants

The following constants denoting individual bits are defined by the standard library:

Name Explanation
async the task is executed on a different thread, potentially by creating and launching it first
deferred the task is executed on the calling thread the first time its result is requested (lazy evaluation)

In addition, implementations are allowed to:

  • define additional bits and bitmasks to specify restrictions on task interactions applicable to a subset of launch policies, and
  • enable those additional bitmasks for the first (default) overload of std::async.

[edit] Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
LWG 2102 C++11 std::launch was an implementation-defined type it is not implementation-defined

[edit] See also

(C++11)
runs a function asynchronously (potentially in a new thread) and returns a std::future that will hold the result
(function template) [edit]