InterlockedExchange64



Hi all,

I am studying the InterlockedExchange64 function behavior and i think
I did sth wrong. IMO, the line that contains teh call
to ::DebugBreak() shouldn´t neve be executed. Am I right?


//////////////////////////////////////////////////////////////////////

volatile __int64 g;


unsigned __stdcall Check(void*)
{
__int64 t;

::InterlockedExchange64(&t, g);

while ((t == 0) ||
(t == 0xffffffffffffffff))
{
::InterlockedExchange64(&t, g);
}


::DebugBreak(); // THIS SHOULDN´T HAPPENS! SHOULD IT?

cout << std::hex << t;

return 0L;
}


int main(int argc, char **argv)
{
::_beginthreadex(NULL, 0, Check, NULL, 0, NULL);

__int64 v[] = {0, 0xffffffffffffffff};

int i = 0;

while (TRUE)
{
::InterlockedExchange64(&g, v[i %= 2, i++]);
}


return 0;
}

//////////////////////////////////////////////////

Best Regards.

.



Relevant Pages

  • Re: function returning __int32 in place of __int64
    ... > number (assigned to a __int64 var). ... function returns an int, which is 32 bits on your platform. ... Then include "my_header.h" in all the source files. ... to be an int value, if it fits in an int, or a long value. ...
    (comp.dsp)
  • Re: C and only C language has a standard 64 bit integer type ?
    ... > a new keyword, it's a correction in the grammar. ... int16 is introduced and is an exact 16-bit type (of course additional ... int and short become equivalent of it. ... int64 is introduced and holds 64-bit values. ...
    (comp.lang.cpp)
  • Re: Proposal: New types in C++0x
    ... > is unsigned int16 to be the same as unsigned int and unsigned, ... > and unsigned int64 is the unsigned type. ... If, for example, there exists a platform that ... then replacing int's representation with a 16 bit representation would break ...
    (comp.lang.cpp)
  • Re: Moving from C++ to VC++
    ... >>> At least your code would then capture your requirement for the type. ... Using __int64 just means that int and long wasn't enough, ... We just get yet another long type problem! ...
    (microsoft.public.vc.language)
  • Re: Integer Dos And Donts
    ... While I hadn't really considered Integer being Int64 on 64 bit processors in ... does look like 2 Int32's will be packed nicely into an Int64, ... > Public Shared Sub Main ... > Of course if one really needs a platform specific Int, ...
    (microsoft.public.dotnet.languages.vb)