1

I am forced to run some applications in windows 98 se. vc6 has strange InterlockedCompareExchange definition:

void* InterlockedCompareExchange(void**, void*, void*);

msdn defines it like this however (since windows xp):

LONG InterlockedCompareExchange(LONG*, LONG, LONG);

Does anyone remembers how to use it (I need to atomically get value of interlocked variable)?

Ivars
  • 2,375
  • 7
  • 22
  • 31
  • IIRC, it doesn't matter: Win98 didn't have threads anyway. – MSalters Mar 04 '14 at 13:26
  • 2
    @MSalters: Sure it did. – 500 - Internal Server Error Mar 04 '14 at 13:30
  • @MSalters `win98` has threads and it has other `Interlocked*` functions as well. – Ivars Mar 04 '14 at 13:37
  • Well, they've been designed to be API-compatible with Windows NT, which had multi-CPU support since 3.1 or so. Doesn't mean Win9x actually supported a second CPU or dual-core CPU, it did have the API functions but still executed one thread at a time. – MSalters Mar 04 '14 at 13:40
  • @MSalters yes it's all about simulation in manner of fast switching between threads but it doesn't make operations atomic. i still need to atomically check my variable. – Ivars Mar 04 '14 at 13:46

1 Answers1

1

Windows 98 did not support 64bit, so void* and LONG are the same byte size. Most OSes actually use the LONG definition, but if VC6 is using `void* then simply type-cast where needed:

LONG value;
LONG ret = (LONG) InterlockedCompareExchange((void**)&value, (void*)ExchangeValue, (void*)CompareValue);
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770