void foo() { static int id = 0; const int local_id = id++; //do something with local_id; }
Multiple threads can call foo in parallel mu
Your code is not thread safe because two threads may increment id at the same time.
Use mutual exclusion or std::atomic for the shared id variable.