arXiv:2609.00246cs.PLAug 2026

Manuscript Offprint

arXiv:2609.00246

Beyond Locks and Thread IDs: Static Data Race Detection Off The Beaten Path (Extended Version)

Daniel Bund, Julian Erhard, Michael Petter, Michael Schwarz

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Daniel Bund 1^{1} ID^{ID}, Julian Erhard 2^{2} ID^{ID}, Michael Petter 1^{1} ID^{ID}, and Michael Schwarz 3^{3} ID^{ID}

1^{1} Technical University of Munich, Garching, Germany

{daniel.bund,michael.petter}@tum.de

2^{2} CISPA Helmholtz-Zentrum, Garching, Germany

julian.erhard@cispa.de

3^{3} National University of Singapore, Singapore

m.schwarz@nus.edu.sg

Abstract. Maintaining an abstraction of the execution history of threads can improve the precision of data race detection in static analysis. Here, we extend the digest framework to handle concurrency constructs and synchronization mechanisms that have been ignored in static race detection. We introduce mechanisms for the commonly used thread barriers, as well as pthread_once, which allows to ensure that an action is executed only once. We also instantiate the framework with an abstraction of locksets held by ancestor threads. We propose a suite of litmus tests to evaluate analyses for these features and compare our implementation to state-of-the-art tools, finding that they lack support.

Keywords: data races, concurrency, static program analysis, software verification, abstract interpretation

1 Introduction

Data races are a class of errors that is particularly hard to debug, partially due to the nondeterministic nature of the scheduling, i.e., bugs not materializing in every execution. To ensure correctness of code, particularly in domains where bugs are unacceptable, sound static analyses have been proposed that are guaranteed to flag any potential data race. However, these analyses typically suffer from false positives. For such tools to be practical, the number of false positives must remain manageable [3, 11]. Nevertheless, much of the literature on static data-race detection considers only mutexes and thread creation and joining as synchronization, overlooking less common but equally valid ways to prevent conflicting accesses from occurring concurrently. One such feature are barriers as provided by PTHREADS:

Example 1. Figure 1 is a program fragment using barriers. The main thread creates two workers, which compute with the value of a global variable g and their string argument. The barrier b is used to ensure that both workers can only

D. Bund, J. Erhard, M. Petter, and M. Schwarz

int g; pthread_barrier_t b; void* worker(void* arg) { // Worker initialization pthread_barrier_wait(&b); int f = compute(g, arg); // Do something with f return NULL; }

int main() { pthread_t w1, w2; // Worker threads pthread_barrier_init(&b, NULL, 3); pthread_create(&w1, NULL, worker, "1"); pthread_create(&w2, NULL, worker, "2"); // Main initialization code g = 2; pthread_barrier_wait(&b); // ... }

Fig. 1. Program using PTHREADS barriers.

perform their computation (line 10) after the main thread has set the global in line 24. Once all three threads have called wait for b, all of them can proceed. Assuming that the variable g is only accessed in the three locations given in the program fragment, there is no data race: The write to g in line 24 happens before all threads have reached the barrier, and the other two accesses to g happen later.

On top of synchronization by barriers, we also consider the pthread_once feature library developers often rely on (see the example Figure 4 in Section 3) and two patterns combining reasoning about threads and synchronization by mutexes (see the descendantLocksets example in Figure 8 in Section 5, as well as the creationLocksets examples in Figure 9).

We focus on the temporal aspect of race detection, providing sound methods to prove that two access instructions cannot happen in parallel. This takes different forms: For barriers, our approach determines that certain accesses must happen before others. For pthread_once, this is combined with establishing that all accesses protected by the same pthread_once control variable happen in the same thread and can thus not race, even when their specific order cannot be established. When it comes to reasoning about threads and mutexes, in the descendantLocksets case (Section 5), it is once more must-happen-before relationships that are established, while for creationLocksets (Appendix F), it is only the fact that accesses are in fact ordered by critical sections even though they may not appear to be at first glance. Broadly, these mechanisms fall into two categories: barriers, pthread_once, and descendant locksets use additional history information to establish must-happen-before relationships between accesses, whereas creation locksets (Appendix F) extend conventional lockset reasoning by recognizing protection through critical sections spanning multiple threads.

Our approach is parametric in the other important ingredient of static race detection, namely a may-alias analysis, and can be combined with different such analyses to obtain different speed–precision tradeoffs.

We base our work on digest-driven abstract interpretation. Abstract interpretation [4] is a principled way to overapproximate the concrete semantics of programs using abstract domains. Digests [28] were originally designed as a mechanism to improve the precision of thread-modular value analyses using abstract interpretation. Digests allow an analysis to distinguish program points as well as the states of shared variables according to the execution history observed by the thread executing the statement. They thus generalize trace partitioning [20] to concurrent programs, providing concurrency-sensitivity that can be configured independently of the analysis domain. In the result computed by an analysis with digests, potentially reachable accesses to shared variables are annotated with digests, i.e., an abstraction of the execution history observed by the thread in question. This can be exploited to enhance the precision of sound static data race detection [26]: When considering two accesses to a shared variable, both annotated with a digest, data races can be excluded when the two accesses cannot happen concurrently—as judged by their digests.

While previous work [25, 26, 28] proposes digests for history information such as whether the execution is single-threaded or multi-threaded, or which mutexes are locked by the current thread, libraries such as PTHREADS offer further concurrency and synchronization primitives, which have often been ignored. In particular, we provide digests for barriers, a mechanism to synchronize multiple threads. To do so, we extend the semantic framework underlying the digest framework to actions that involve more than two threads (Section 2). We show how digests are used to argue about whether two arbitrary operations may possibly happen in parallel 4^{4}, which is not only a key ingredient of our barrier digest but also paves the way towards further applications of the digest framework.

We show in Section 4 how a history abstraction, i.e., a digest, relating to the operations performed on the barrier, is used to deduce race freedom for the programs using barriers, such as Example 1. There, the predicate ∥?\|^{?}, introduced for checking whether two accesses to the same variable may race, is used for a different purpose in the definition of the barrier digest itself, to determine whether a sufficient number of threads may wait at the barrier at the same time.

Section 3 proposes a digest for pthread_once for more precise data-race detection. pthread_once is a feature used in particular by library developers to ensure that some code is executed exactly once.

Sometimes a thread locks a mutex before creating child threads and does not release it until certain protected operations have completed. This pattern requires intricate handling beyond existing per-thread lockset analyses. Partially inspired by Lu et al. [19], we propose a way of handling such patterns with digests in Section 5. Another pattern, where locks are held by a thread during the entire execution of its child is covered in Section 6. We implemented the proposed digests in an abstract interpreter. The experiments we conducted on a set of hand-crafted examples using these constructs are discussed in Section 7.

References (34)