I have introduced In the post Sequential Consistency the default memory model. This model, in which all operations in all threads takes place in a global time clock, has a big advantage but also a big disadvantage.
In this post, our tour through the c++ memory model goes one step deeper. Until now, the posts were only about the atomicity of the atomic data types but now we deal with the synchronisation and ordering constraints of the operations.
In addition to booleans, there is atomics for pointers, integrals and user-defined types. The rules for user-defined types are special.
The remaining atomics - in contrast to std::atomic_flag - are partial or full specialisations of the class template std::atomic. Let's start with std::atomic<bool>.
Atomics guarantee two characteristics. At one hand, they are atomic, at the other hand, they provide synchronisation and order constraints on the program execution.
The atomics are the base of the C++ memory model. Per default, sequential consistency is applied.
Since C++11, C++ has a memory model. It is the foundation for multithreading. Without it, multithreading is not well defined.
In case you are using promise and future to synchronize threads, they have a lot in common with condition variables. But most of the time, task are the better choice.
The parent of a thread has to take care of their child. The parent can wait until its child is done or detach itself from its child. But that is not really new. But that will not hold for std::async. The big charm of std::async is, that the parent has not taken care of its child.
With std::promise and std::future, you have full control over the task.
Currently are 189 guests and no members online
Kubik-Rubik Joomla! Extensions