#include <iostream>
#include <thread>
void job1()
{
static int data = 42;
std::cout << data << std::endl;
++data;
}
void job2()
{
thread_local static int data = 42;
std::cout << data << std::endl;
++data;
}
int main()
{
std::cout << "Job1" << std::endl;
for (int i=0; i<10; ++i)
{
std::thread t{ job1 };
t.join();
}
std::cout << "Job2" << std::endl;
for (int i=0; i<10; ++i)
{
std::thread t{ job2 };
t.join();
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dGhyZWFkPgoKdm9pZCBqb2IxKCkKewogICAgc3RhdGljIGludCBkYXRhID0gNDI7CiAgICBzdGQ6OmNvdXQgPDwgZGF0YSA8PCBzdGQ6OmVuZGw7CiAgICArK2RhdGE7Cn0KCnZvaWQgam9iMigpCnsKICAgIHRocmVhZF9sb2NhbCBzdGF0aWMgaW50IGRhdGEgPSA0MjsKICAgIHN0ZDo6Y291dCA8PCBkYXRhIDw8IHN0ZDo6ZW5kbDsKICAgICsrZGF0YTsKfQoKaW50IG1haW4oKQp7CiAgICBzdGQ6OmNvdXQgPDwgIkpvYjEiIDw8IHN0ZDo6ZW5kbDsKICAgIGZvciAoaW50IGk9MDsgaTwxMDsgKytpKQogICAgewogICAgICAgIHN0ZDo6dGhyZWFkIHR7IGpvYjEgfTsKICAgICAgICB0LmpvaW4oKTsKICAgIH0KICAgIAogICAgc3RkOjpjb3V0IDw8ICJKb2IyIiA8PCBzdGQ6OmVuZGw7CiAgICBmb3IgKGludCBpPTA7IGk8MTA7ICsraSkKICAgIHsKICAgICAgICBzdGQ6OnRocmVhZCB0eyBqb2IyIH07CiAgICAgICAgdC5qb2luKCk7CiAgICB9CiAgICAKICAgIHJldHVybiAwOwp9