--- description: "Learn more about: Warning C26160" title: Warning C26160 ms.date: 11/04/2016 f1_keywords: ["C26160"] helpviewer_keywords: ["C26160"] ms.assetid: e6518687-36b4-4eae-a732-758881638295 --- # Warning C26160 > Caller possibly failing to hold lock '*lock*' before calling function '*func*'. Warning C26160 resembles warning [C26110](../code-quality/c26110.md) except that the confidence level is lower. For example, the function may contain annotation errors. ## Examples The following code generates warning C26160. ```cpp struct Account { _Guarded_by_(cs) int balance; CRITICAL_SECTION cs; _No_competing_thread_ void Init() { balance = 0; // OK } _Requires_lock_held_(this->cs) void FuncNeedsLock(); _No_competing_thread_ void FuncInitCallOk() // this annotation requires this function is called // single-threaded, therefore we don't need to worry // about the lock { FuncNeedsLock(); // OK, single threaded } void FuncInitCallBad() // No annotation provided, analyzer generates warning { FuncNeedsLock(); // Warning C26160 } }; ``` The following code shows a solution to the previous example. ```cpp struct Account { _Guarded_by_(cs) int balance; CRITICAL_SECTION cs; _No_competing_thread_ void Init() { balance = 0; // OK } _Requires_lock_held_(this->cs) void FuncNeedsLock(); _No_competing_thread_ void FuncInitCallOk() // this annotation requires this function is called // single-threaded, therefore we don't need to worry // about the lock { FuncNeedsLock(); // OK, single threaded } void FuncInitCallBadFixed() // this function now properly acquires (and releases) the lock { EnterCriticalSection(&this->cs);FuncNeedsLock();LeaveCriticalSection(&this->cs); } }; ```