ID generator with local static variable - thread-safe?
- by Poseidon
Will the following piece of code work as expected in a multi-threaded scenario?
int getUniqueID()
{
static int ID=0;
return ++ID;
}
It's not necessary that the IDs to be contiguous - even if it skips a value, it's fine.
Can it be said that when this function returns, the value returned will be unique across all threads?