Skip to content

Commit 5acdc3c

Browse files
committed
Fix TSAN data races
------------------------------------------------------ As found in #71, tsan reported several issues in the acl_test Currently when release command queue are called (which frees the memory) subsequent still checks the values at the same address which cause tsan to report heap-use-after-free.
1 parent 8cd410f commit 5acdc3c

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ if(ACL_CODE_COVERAGE)
6868
endif()
6969
endif()
7070

71+
# Flag for tsan scans
72+
option(ACL_TSAN "Build with tsan" OFF)
73+
message(STATUS "Build with tsan: ${ACL_TSAN}")
74+
if(ACL_TSAN)
75+
if(CMAKE_COMPILER_IS_GNUCXX)
76+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ltsan -fsanitize=thread -g -O1 -fno-omit-frame-pointer -fPIC")
77+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ltsan -fsanitize=thread -g -O1 -fno-omit-frame-pointer -fPIC")
78+
else()
79+
message(FATAL_ERROR "cannot build with tsan tools due to unsupported CXX compiler")
80+
endif()
81+
endif()
82+
7183
################################################################################
7284
### Modified Debug flags
7385
################################################################################

test/acl_command_queue_test.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,6 @@ MT_TEST(acl_command_queue, create_with_properties) {
387387
CHECK_EQUAL(CL_SUCCESS, clReleaseCommandQueue(cq));
388388
CHECK_EQUAL(1, acl_ref_count(cq));
389389
CHECK_EQUAL(CL_SUCCESS, clReleaseCommandQueue(cq));
390-
CHECK_EQUAL(0, acl_ref_count(cq));
391-
ACL_LOCKED(CHECK(!acl_command_queue_is_valid(cq)));
392390

393391
// wait until all threads do their checks on the 0-ref-count command
394392
// queue before starting the next iteration of the loop and creating new
@@ -421,8 +419,6 @@ MT_TEST(acl_command_queue, create_with_properties) {
421419
CHECK_EQUAL(CL_SUCCESS, clReleaseCommandQueue(cq));
422420
CHECK_EQUAL(1, acl_ref_count(cq));
423421
CHECK_EQUAL(CL_SUCCESS, clReleaseCommandQueue(cq));
424-
CHECK_EQUAL(0, acl_ref_count(cq));
425-
ACL_LOCKED(CHECK(!acl_command_queue_is_valid(cq)));
426422

427423
// wait until all threads do their checks on the 0-ref-count command
428424
// queue before starting the next iteration of the loop and creating new
@@ -674,15 +670,6 @@ MT_TEST(acl_command_queue, after_context_release) {
674670
// Should be able to release all the way.
675671
CHECK_EQUAL(CL_SUCCESS, clReleaseCommandQueue(cq0));
676672
CHECK_EQUAL(CL_SUCCESS, clReleaseCommandQueue(cq1));
677-
CHECK_EQUAL(0, acl_ref_count(cq0));
678-
CHECK_EQUAL(0, acl_ref_count(cq1));
679-
680-
ACL_LOCKED(CHECK(!acl_command_queue_is_valid(cq0)));
681-
ACL_LOCKED(CHECK(!acl_command_queue_is_valid(cq1)));
682-
683-
// And once it's gone, it's gone.
684-
CHECK_EQUAL(CL_INVALID_COMMAND_QUEUE, clReleaseCommandQueue(cq0));
685-
CHECK_EQUAL(CL_INVALID_COMMAND_QUEUE, clReleaseCommandQueue(cq1));
686673
}
687674

688675
// Main Event is in an OOO queue. It has a dependent event in an in-order queue.

0 commit comments

Comments
 (0)