Re: How to do atomic read?

Tech-Archive recommends: Fix windows errors by optimizing your registry



If another processor changes the variable in between reading (pushing to the
stack) and calling InterlockedExchange, its contents would be replaced to
the previous. This is not what you want.

<0dbell@xxxxxxxxx> wrote in message
news:1182347341.060002.164730@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Jun 20, 9:11 am, "Alexander Grigoriev" <a...@xxxxxxxxxxxxx> wrote:
<0db...@xxxxxxxxx> wrote in message

But, in case I am not seeing the obvious, what's wrong with:

LONG asignee = InterlockedExchange(&var, var);

First, it's NOT atomic. There is a window for change. This IS atomic:

LONG asignee = InterlockedCompareExchange(&var, 0, 0);

Thanks for the correction. Can you explain why?

And what's Second?

Regards,
Don



.