Skip to content

Commit

Permalink
test: generate race on static variable
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoessbauer committed May 25, 2020
1 parent f2136ad commit 20bda01
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions test/mini-apps/concurrent-inc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ add_executable(${EXAMPLE} "main")
target_link_libraries(${EXAMPLE} Threads::Threads)
set_target_properties(${EXAMPLE} PROPERTIES CXX_STANDARD 11)

add_executable("${EXAMPLE}-static" "main")
target_link_libraries("${EXAMPLE}-static" Threads::Threads)
set_target_properties("${EXAMPLE}-static" PROPERTIES CXX_STANDARD 11)
target_compile_definitions("${EXAMPLE}-static" PRIVATE USE_STATIC)

if(DRACE_INSTALL_TESTS)
install(TARGETS ${EXAMPLE} DESTINATION ${DRACE_RUNTIME_DEST})
install(TARGETS "${EXAMPLE}-static" DESTINATION ${DRACE_RUNTIME_DEST})
endif()
9 changes: 6 additions & 3 deletions test/mini-apps/concurrent-inc/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DRace, a dynamic data race detector
*
* Copyright 2018 Siemens AG
* Copyright 2020 Siemens AG
*
* Authors:
* Felix Moessbauer <felix.moessbauer@siemens.com>
Expand All @@ -14,9 +14,9 @@
#include <thread>

#define NUM_INCREMENTS 10000
#define USE_HEAP

// std::mutex mx;
// #define USE_HEAP // race on the heap
// #define USE_STATIC // race on a static variable

void inc(int* v) {
for (int i = 0; i < NUM_INCREMENTS; ++i) {
Expand All @@ -39,6 +39,9 @@ int main() {
#ifdef USE_HEAP
int* mem = new int[1];
*mem = 0;
#elif USE_STATIC
static int var = 0;
int* mem = &var;
#else
int var = 0;
int* mem = &var;
Expand Down

0 comments on commit 20bda01

Please sign in to comment.