std::call_once 确保这个函数只会被调用一次。
#include <thread>
#include <mutex>
#include <iostream>
#include <unistd.h>
std::once_flag flag1;
inline void hi(int i){
std::cout << "Simple example: called once "<< i << std::endl;
}
void simple_do_once()
{
std::call_once(flag1,hi,100);
}
int main() {
simple_do_once();
simple_do_once();
simple_do_once();
}