C26111

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

warning C26111: 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 cannot 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);  
}  
  

Show: