Easy
A thread_local counter incremented from two threads and main
What values does this print for counter across the three calls (via t1, via t2, and the main-thread call), in whatever order they happen to print?
main.cpp
thread_local int counter = 0;
void increment(int n) {
for (int i = 0; i < n; ++i) ++counter;
std::cout << "counter = " << counter << std::endl;
}
int main() {
std::thread t1(increment, 5);
std::thread t2(increment, 10);
t1.join();
t2.join();
increment(3);
}11 of 51 in Concurrency