C26160
Uyarı C26160: Arayanın <func> işlevini çağırmadan önce <lock>kilidini tutmasının başarısız olması olasıdır.
Uyarı C26160; C26110 uyarasına güvenilirlik düzeyini daha düşük olması dışında benzer.Örneğin, işlev ek açıklama ekleme hataları içerebilir.
Örnek
Aşağıdaki kod C26160 uyarı oluşturur.
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
}
};
Aşağıdaki kod önceki örnek çözüm gösterir.
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);
}
};