If your application were single-threaded, the code you posted would be in fact the correct, standards-compliant C/C++ way of generating unique numbers. However, since you're looking for a thread-safe solution, you must dive into platform-specific solutions. Goz has a good Windows solution. An equivalent on Mac OS X or iOS would be:
int returnUniqueNumber_APPLE(void) {
static volatile int32_t i = 0;
return (int)OSAtomicIncrement32Barrier(&i);
}
On any system where you compile with a recent-ish GCC, you also have GCC's intrinsics:
int returnUniqueNumber_GCC(void) {
static volatile int i = 0;
return __sync_add_and_fetch(&i, 1);
}