no edit summary
C++ 11 Threads on the contrary always required to specify the number of threads required for a parallel region. If not specified by user input or hard-coding, the number of threads supported by a CPU can also be accurately via the std::thread::hardware_concurrency(); function.
OpenMp automatically decides what order threads will execute. C++ 11 Threads require the developer to specify in what order threads will execute. This is typically done within a for loop block. Threads are created by initializing the std::thread class and specifying a function or any other callable object within the constructor.
Example of native thread creating and synchronization using C++ 11
int numThreads = std::thread::hardware_concurrency();
threads[ID] = std::thread(function);
Each created thread can then be synchronized with the main thread
C++ 11 threads and language native threads unfortunately lack this luxury. In order to parallelize a loop using std Threads, it is the programmers responsibility to calculate the range of each iteration within the loop the be parallelized. This is usually done using SPMD techniques.
C++ 11 and Openmp are designed to avoid race conditions and share data between threads in various ways.
Openmp Handles Mutual Exclusion by
for (int i = 1000; i > 0; i--)
shared_output("main thread", i);