Avertissement C26101
Échec de l’utilisation de l’opération interblocée correctement pour la variable « var ».
Les API Windows offrent différentes opérations interblocées. L’annotation _Interlocked_
spécifie qu’une variable ne doit être accessible qu’à l’aide d’une opération interblocée. Avertissement C26101 est émis lorsqu’un accès variable n’est pas cohérent avec l’annotation _Interlocked_
.
Exemple
L’exemple suivant génère un avertissement C26101, car il existe une violation du _Interlocked_
contrat.
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);
}