Skip to content

Instantly share code, notes, and snippets.

@tiandiao123
Created December 19, 2022 21:32
Show Gist options
  • Save tiandiao123/3cc84f2a3ad678ba345c06f2205871fa to your computer and use it in GitHub Desktop.
Save tiandiao123/3cc84f2a3ad678ba345c06f2205871fa to your computer and use it in GitHub Desktop.
#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