views:

94

answers:

1

Hi;

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

+1  A: 

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