/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, OCaml, VB, Perl, Swift, Prolog, Javascript, Pascal, COBOL, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <mutex>
#include <cstdio>
#include <thread>
void fooCallOnceVersion() {
static std::once_flag once;
std::call_once(once, []() {
std::printf("Foo call once\n");
});
}
void fooStaticVersion() {
static auto printLog = []() {
return std::printf("Foo static version\n");
}();
}
int main()
{
std::thread t1(fooCallOnceVersion), t2(fooCallOnceVersion), t3(fooStaticVersion), t4(fooStaticVersion);
t1.join();
t2.join();
t3.join();
t4.join();
return 0;
}