We recommend using Visual Studio 2017

C26101

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at C26101.

warning C26101: Failing to use interlocked operation properly for variable <var>.

Windows APIs offer a variety of interlocked operations. Annotation _Interlocked_ specifies that a variable should only be accessed through an interlocked operation. Warning C26101 is issued when an access is not consistent with the _Interlocked_ annotation.

The following example generates warning C26101 because there is a violation of the _Interlocked_ contract.

  
CRITICAL_SECTION cs;  
typedef struct _DATA   
{  
    _Interlocked_ LONG data;  
} DATA;  
  
void Safe(DATA* p)   
{  
    InterlockedIncrement(&p->data); // OK  
}  
  
void Unsafe(DATA* p)   
{  
    p->data += 1; // Warning C26101  
    EnterCriticalSection(&cs);  
    LeaveCriticalSection(&cs);  
}  
  

Show: