---
title: "CWE-366: Race Condition within a Thread"
url: https://radicalnotion.ai/cwe/cwe-366
type: cwe
description: "If two threads of execution use a resource simultaneously, there exists the possibility that resources may be used while invalid, in turn making the state of execution undefined."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-366: Race Condition within a Thread

- **Abstraction:** Base
- **Structure:** Simple
- **Status:** Draft
- **Likelihood of exploit:** Medium
- **CVEs with this as primary weakness:** 184
- **Of those, in CISA KEV:** 0
- **New in 2026:** 122
- **CWE catalog version:** 4.21

## Description

If two threads of execution use a resource simultaneously, there exists the possibility that resources may be used while invalid, in turn making the state of execution undefined.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | - |

## Applicable platforms

**Languages:** C (Undetermined), C++ (Undetermined), Java (Undetermined), C# (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity, Other | Alter Execution Logic, Unexpected State | The main problem is that -- if a lock is overcome -- data could be altered in a bad state. |

## Potential mitigations

### Architecture and Design

Use locking functionality. This is the recommended solution. Implement some form of locking mechanism around code which alters or reads persistent data in a multithreaded environment.

### Architecture and Design

Create resource-locking validation checks. If no inherent locking mechanisms exist, use flags and signals to enforce your own blocking scheme when resources are being used by other threads of execution.

## Detection methods

### Automated Static Analysis

Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

Effectiveness: High

## Demonstrative examples

### Example 1

The following example demonstrates the weakness.

Bad code:

```c
int foo = 0;
int storenum(int num) {
    static int counter = 0;
    counter++;
    if (num > foo) foo = num;
    return foo;
}
```

Bad code:

```java
public classRace {
    static int foo = 0;
    public static void main() {

        new Threader().start();
        foo = 1;
    }
    public static class Threader extends Thread {

        public void run() {
            System.out.println(foo);
        }
    }
}
```

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2022-2621 | Chain: two threads in a web browser use the same resource (CWE-366), but one of those threads can destroy the resource before the other has completed (CWE-416). |

## Real CVEs with this weakness (sample of 12 of 184)

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2026-98338 | wifi: cfg80211: ibss: ref BSS entry for joined event | critical | 9.8 | - | No | 2026-10-06 |
| CVE-2026-98337 | wifi: mac80211: don't start a ROC while scanning | critical | 9.8 | - | No | 2026-10-06 |
| CVE-2026-98252 | RDMA/core: fix refcount bug in iwpm\_get\_nlmsg\_request() | critical | 9.8 | - | No | 2026-10-06 |
| CVE-2026-89972 | nvme: add missing SRCU grace period in error path | critical | 9.8 | - | No | 2026-09-16 |
| CVE-2026-80980 | net/smc: stop killed, freed and out\_of\_sync sharing a byte | critical | 9.8 | - | No | 2026-09-11 |
| CVE-2026-72494 | RDMA/irdma: Replace waitqueue and flag with completion | critical | 9.8 | - | No | 2026-08-15 |
| CVE-2026-72221 | sunrpc: wait for in-flight TLS handshake callback when cancel loses race | critical | 9.8 | - | No | 2026-08-15 |
| CVE-2023-54292 | RDMA/irdma: Fix data race on CQP request done | critical | 9.8 | - | No | 2025-12-30 |
| CVE-2025-68745 | scsi: qla2xxx: Clear cmds after chip reset | critical | 9.8 | - | No | 2025-12-24 |
| CVE-2025-68341 | veth: reduce XDP no\_direct return section to fix race | critical | 9.8 | - | No | 2025-12-23 |
| CVE-2025-40257 | mptcp: fix a race in mptcp\_pm\_del\_add\_timer() | critical | 9.8 | - | No | 2025-12-04 |
| CVE-2025-58143 | Mutiple vulnerabilities in the Viridian interface | critical | 9.8 | - | No | 2025-09-11 |

## Related attack patterns (CAPEC)

- [CAPEC-26](https://radicalnotion.ai/capec/capec-26): Leveraging Race Conditions
- [CAPEC-29](https://radicalnotion.ai/capec/capec-29): Leveraging Time-of-Check and Time-of-Use (TOCTOU) Race Conditions

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-362](https://radicalnotion.ai/cwe/cwe-362) | Concurrent Execution using Shared Resource with Improper Synchronization |
| Parent | [CWE-662](https://radicalnotion.ai/cwe/cwe-662) | Improper Synchronization |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| CLASP | Race condition within a thread | - | - |
| CERT C Secure Coding | Prevent data races when accessing bit-fields from multiple threads | CON32-C | CWE More Abstract |
| CERT C Secure Coding | Do not refer to an atomic variable twice in an expression | CON40-C | CWE More Abstract |
| CERT C Secure Coding | Do not allow data races in multithreaded code | CON43-C | Exact |
| The CERT Oracle Secure Coding Standard for Java (2011) | Ensure that compound operations on shared variables are atomic | VNA02-J | - |
| The CERT Oracle Secure Coding Standard for Java (2011) | Do not assume that a group of calls to independently atomic methods is atomic | VNA03-J | - |
| Software Fault Patterns | Missing Lock | SFP19 | - |

## Frequently asked questions

### What is CWE-366?

If two threads of execution use a resource simultaneously, there exists the possibility that resources may be used while invalid, in turn making the state of execution undefined.

### What CVEs are caused by CWE-366?

184 recorded CVEs are attributed to CWE-366, including CVE-2026-98338, CVE-2026-98337 and CVE-2026-98252.

### How do you prevent CWE-366?

Use locking functionality. This is the recommended solution. Implement some form of locking mechanism around code which alters or reads persistent data in a multithreaded environment.

### How is CWE-366 detected?

Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

### What are the consequences of CWE-366?

Exploiting CWE-366 can lead to: Alter Execution Logic, Unexpected State.

### Is CWE-366 actively exploited?

184 recorded CVEs are caused by CWE-366; none are currently in CISA's KEV catalog of actively exploited flaws.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/366.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-366). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
