Skip to content

Latest commit

 

History

History
63 lines (51 loc) · 1.67 KB

c26130.md

File metadata and controls

63 lines (51 loc) · 1.67 KB
description title ms.date ms.topic f1_keywords helpviewer_keywords ms.assetid
Learn more about: C26130
C26130
11/04/2016
reference
C26130
C26130
535e2356-bc84-4549-983d-7d29aee2249c

C26130

warning C26130: Missing annotation _Requires_lock_held_(<lock>) or _No_competing_thread_ at function <func>. Otherwise it could be a race condition. Variable <var> should be protected by lock <lock>.

Warning C26130 is issued when the analyzer detects a potential race condition but infers that the function is likely to be run in a single threaded mode, for example, when the function is in the initialization stage based on certain heuristics.

Examples

In the following example, warning C26130 is generated because a _Guarded_by_ member is being modified without a lock.

typedef struct _DATA
{
    CRITICAL_SECTION cs;
    _Guarded_by_(cs) int data;
} DATA;

void Init(DATA* p)
{
    p->data = 0; // Warning C26130
}

If the previous code is guaranteed to be operated in a single threaded mode, annotate the function by using _No_competing_thread_, as shown in the following example.

typedef struct _DATA
{
    CRITICAL_SECTION cs;
    _Guarded_by_(cs) int data;
} DATA;

_No_competing_thread_ void Init(DATA* p)
{
    p->data = 0; // Warning C26130 will be resolved
}

Alternatively, you can annotate a code fragment by using _No_competing_thread_begin_ and _No_competing_thread_end_, as follows.

typedef struct _DATA
{
    CRITICAL_SECTION cs;
    _Guarded_by_(cs) int data;
} DATA;

void Init(DATA* p)
{
    _No_competing_thread_begin_
    p->data = 0; // Warning C26130 will be resolved
    _No_competing_thread_end_
}