We recommend using Visual Studio 2017

C26111

 

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 C26111.

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: