Re: How to do atomic read?
- From: "Alexander Grigoriev" <alegr@xxxxxxxxxxxxx>
- Date: Wed, 20 Jun 2007 20:46:38 -0700
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
.
- References:
- How to do atomic read?
- From: vasanth
- Re: How to do atomic read?
- From: 0dbell
- Re: How to do atomic read?
- From: Alexander Grigoriev
- Re: How to do atomic read?
- From: 0dbell
- How to do atomic read?
- Prev by Date: Re: How to do atomic read?
- Next by Date: Re: How to do atomic read?
- Previous by thread: Re: How to do atomic read?
- Next by thread: Re: How to do atomic read?
- Index(es):