--- description: "Learn more about: Warning C26116" title: Warning C26116 ms.date: 11/04/2016 f1_keywords: ["C26116"] helpviewer_keywords: ["C26116"] ms.assetid: 43e99d2c-405e-4913-b6bd-47f5858b2877 --- # Warning C26116 > Failing to acquire or to hold lock '*lock*' in '*func*'. Enforcement of syntactically scoped lock *acquire* and lock *release* pairs in C/C++ programs isn't performed by the language. A function may introduce a locking side effect by making an observable modification to the concurrency state. For example, a lock wrapper function increments the number of lock acquisitions, or lock count, for a given lock. You can annotate a function that has a side effect from a lock acquire or lock release by using `_Acquires_lock_` or `_Requires_lock_held`, respectively. Without such annotations, a function is expected not to change any lock count after it returns. If acquires and releases aren't balanced, they're considered to be *orphaned*. Warning C26116 is issued when a function has been annotated with `_Acquires_lock_`, but it doesn't acquire a lock, or when a function is annotated with `_Requires_lock_held` and releases the lock. ## Example The following example generates warning C26116 because the function `DoesNotLock` was annotated with `_Acquires_lock_` but doesn't acquire it. The function `DoesNotHoldLock` generates the warning because it's annotated with `_Requires_lock_held` and doesn't hold it. ```cpp typedef struct _DATA { CRITICAL_SECTION cs; } DATA; _Acquires_lock_(p->cs) void DoesLock(DATA* p) { EnterCriticalSection(&p->cs); // OK } _Acquires_lock_(p->cs) void DoesNotLock(DATA* p) { // Warning C26116 } _Requires_lock_held_(p->cs) void DoesNotHoldLock(DATA* p) { LeaveCriticalSection(&p->cs); // Warning C26116 } ``` ## See also - [C26115](../code-quality/c26115.md)