共用方式為


_InterlockedAnd, _InterlockedAnd64

Microsoft Specific

Used to perform an atomic AND operation on a variable shared by multiple threads.

long _InterlockedAnd(
   long volatile * value,
   long mask
);
long _InterlockedAnd_acq(
   long volatile * value,
   long mask
);
long _InterlockedAnd_rel(
   long volatile * value,
   long mask
);
char _InterlockedAnd8(
   char volatile * value,
   char mask
);
char _InterlockedAnd8_acq(
   char volatile * value,
   char mask
);
char _InterlockedAnd8_rel(
   char volatile * value,
   char mask
);
short _InterlockedAnd16(
   short volatile * value,
   short mask
);
short _InterlockedAnd16_acq(
   short volatile * value,
   short mask
);
short _InterlockedAnd16_rel(
   short volatile * value,
   short mask
);
__int64 _InterlockedAnd64(
   __int64 volatile* value,
   __int64 mask
);
__int64 _InterlockedAnd64_acq(
   __int64 volatile* value,
   __int64 mask
);
__int64 _InterlockedAnd64_rel(
   __int64 volatile* value,
   __int64 mask
);

Parameters

  • [in, out] value
    A pointer to the first operand, to be replaced by the result.

  • [in] mask
    The second operand.

Return Value

The original value of the first operand.

Requirements

Intrinsic

Architecture

_InterlockedAnd

x86, IPF, x64

_InterlockedAnd_acq

IPF

_InterlockedAnd_rel

IPF

_InterlockedAnd8

x86, IPF, x64

_InterlockedAnd8_acq

IPF

_InterlockedAnd8_rel

IPF

_InterlockedAnd16

x86, IPF, x64

_InterlockedAnd16_acq

IPF

_InterlockedAnd16_rel

IPF

_InterlockedAnd64

IPF, x64

_InterlockedAnd64_acq

IPF

_InterlockedAnd64_rel

IPF

Header file <intrin.h>

Remarks

The number in the name of each function specifies the bit size of the arguments.

These functions behave as read-write memory barriers. For more information, see _ReadWriteBarrier.

The IPF-specific _InterlockedAnd_acq, _InterlockedAnd8_acq, _InterlockedAnd16_acq, and _InterlockedAnd64_acq intrinsic functions are the same as the corresponding functions without the acq suffix except that the operation is performed with acquire semantics, which is useful when entering a critical section.

The _InterlockedAnd_rel, _InterlockedAnd8_rel, _InterlockedAnd16_rel, and _InterlockedAnd64_rel intrinsic functions are the same as the corresponding functions without the rel suffix except that the operation is performed with release semantics, which is useful when leaving a critical section.

Example

// InterlockedAnd.cpp
// Compile with: /Oi
#include <stdio.h>
#include <intrin.h>

#pragma intrinsic(_InterlockedAnd)

int main()
{
        long data1 = 0xFF00FF00;
        long data2 = 0x00FFFF00;
        long retval;
        retval = _InterlockedAnd(&data1, data2);
        printf_s("0x%x 0x%x 0x%x", data1, data2, retval); 
}
0xff00 0xffff00 0xff00ff00

See Also

Reference

Compiler Intrinsics

Conflicts with the x86 Compiler