Using VC++, to get a unique ID that counts upwards, I was wondering whether this is legal in a multi-threaded application?
uint32_t GetNewId() { return ::InterlockedIncrement(&lastId); }
Basically, I am wondering whether InterlockedIncrement just protects the increment, or whether the return value is also guarded against race conditions?
Yes, that is legal – the access which consists of
will be atomic. Just don’t forget that it’s 32 bit and can overflow.