My notes during learning about implementing multithreading within c++.

OpenMP

use -fopenmp in compilation to enable it. later gcc usually support it example:

g++ tmp.cpp -fopenmp

OpenMP uses #pragma xxxx to support parallelization, the benefit is that the programme can be compiled and get the same result when the compiler does not support it, they will be ignored.

Thread class in C++11

From here:

Basically, it introduces a new class: std::thread, with a member: callable object. Once a new thread object is created, a new thread is launched and the callable object is executed.

callable object = a function pointer or a function object.

e

import<thread>

Summary:

For me , openmp seems to be a better choice if I want to speed things up while not rewrite alot, thread in c++11 provides better control of each thread (like wait it to finish), which is too much.