Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Collapse the table of content
Expand the table of content


warning C26105: Lock order violation. Acquiring lock <lock> with level <level> causes order inversion.

Concurrency SAL supports lock levels. To declare a lock level, which is denoted by a string literal without double quotes, use _Create_lock_level_. You can impose an order of acquisition between two lock levels by using the annotation _Set_lock_level_order_(A,B), which states that locks that have level A must be acquired before locks that have level B. To establish a lock order hierarchy (a partial order among lock levels), use multiple _Set_lock_level_order_ annotations. To associate a lock with a lock level, use the _Set_lock_level_ annotation when you declare the lock. Warning C26105 is issued when a lock ordering violation is detected.

The following example generates warning C26105 because there is a lock order inversion in the function OrderInversion.

_Lock_level_order_(MutexLockLevel, TunnelLockLevel);
_Lock_level_order_(TunnelLockLevel, ChannelLockLevel);
_Has_lock_level_(MutexLockLevel) HANDLE gMutex;

struct Tunnel 
    _Has_lock_level_(TunnelLockLevel) CRITICAL_SECTION cs;

struct Channel 
    _Has_lock_level_(ChannelLockLevel) CRITICAL_SECTION cs;

void OrderInversion(Channel* pChannel, Tunnel* pTunnel) 
    // Warning C26105
    WaitForSingleObject(gMutex, INFINITE); 
© 2015 Microsoft