0

The win32 interlocked functions provide a mecanism for atomic operation on data. They are supposed to be thread-safe and multiprocessor-safe.

What happen if the data is not aligned? the interlocked operations are still atomic? Ex.: incrementing a integer that is not aligned.

Ty

Piotr Dobrogost
  • 41,292
  • 40
  • 236
  • 366

1 Answers1

1

If you read most of the Interlocked API functions, there are remarks that specify something along the lines of:

"The variable pointed to by the Addend parameter must be aligned on a 32-bit boundary; otherwise, this function will behave unpredictably on multiprocessor x86 systems and any non-x86 systems. See _aligned_malloc."

For an example, see this MSDN doc.

This basically says you need to align your data for proper results, using _aligned_malloc.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373