| description | Learn more about: Warning C26111 | |
|---|---|---|
| title | Warning C26111 | |
| ms.date | 11/04/2016 | |
| f1_keywords |
|
|
| helpviewer_keywords |
|
|
| ms.assetid | 85fc740a-3bbb-41b8-a848-95e243a08da9 |
Caller failing to release lock 'lock' before calling function 'func'.
The annotation _Requires_lock_not_held_ imposes a precondition that the lock count for the specified lock can't be greater than zero when the function is called. Warning C26111 is issued when a function fails to release the lock before it calls another function.
The following example generates warning C26111 because the _Requires_lock_not_held_ precondition is violated by the call to DoNotLock within the locked section.
typedef struct _DATA
{
CRITICAL_SECTION cs;
int d;
} DATA;
_Requires_lock_not_held_(p->cs)
void DoNotLock(DATA* p)
{
EnterCriticalSection(&p->cs);
p->d = 0;
LeaveCriticalSection(&p->cs);
}
void LockedFunction(DATA* p)
{
EnterCriticalSection(&p->cs);
DoNotLock(p); // Warning C26111
LeaveCriticalSection(&p->cs);
}