Created
December 19, 2022 21:32
-
-
Save tiandiao123/3cc84f2a3ad678ba345c06f2205871fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <thread> | |
#include <mutex> | |
using namespace std; | |
void SystemInit(){ | |
cout << "hello world! "<< endl; | |
} | |
void SystemInitOnce(){ | |
static std::once_flag flag; | |
std::call_once(flag, SystemInit); | |
} | |
int main(){ | |
thread th(SystemInitOnce); | |
th.join(); | |
for(int i=0;i<4;i++){ | |
cout << "try to init once again ? " << endl; | |
thread th(SystemInitOnce); | |
th.join(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment