- Examples
Let’s discuss the examples of thread-safe initialization of data in this lesson.
We'll cover the following...
We'll cover the following...
Example 1
The short example demonstrates the application of std::call_once and the std::once_flag. Both are declared in the header <mutex>.
Explanation
-
The program starts four threads (lines 17 - 20). Each of them invokes
do_once. The string “only once” is, as a result, displayed only once. ...