Lock-free algorithms: Choosing a unique value (warm-up)

Raymond Chen

Here’s a snippet of code whose job is to generate a unique number within the process. Here’s some reference reading to get yourself in the mood. Caution: It may or may not be useful.

dwUniqueId = InterlockedCompareExchange(&g_dwUniqueId,
                                        g_dwUniqueId+1,
                                        g_dwUniqueId);

Criticize this code fragment.

0 comments

Discussion is closed.

Feedback usabilla icon