How to solve the problem of single case lazy and multithreaded by C++
This article mainly shows you "how C++ solves single-case lazy and multithreaded problems". The content is simple and clear. I hope it can help you solve your doubts. Now let the editor lead you to study and learn this article "how C++ solves single-case lazy and multithreaded problems".
Single-case lazy and multithreaded problems
As a singleton mode, only one memory space is created during the entire program run, in order to achieve this goal.
1. You need to set the constructor as a private member
2. You need a private static pointer to point to yourself
3. You need a public static function to expose the static pointer above.
The following code is an example of a slacker.
Click (here) to collapse or open
# include
Using namespace std
Class single_ins
{
Private:
Int a
Int b
Single_ins ()
{
A = 0
B = 0
}
Static single_ins* myc
Public:
Void setval (const int& a minute Const int& b)
{
This- > a = a
This- > b = b
}
Void print ()
{
Cout