Bug 282794 - TSAN false positive
Summary: TSAN false positive
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: threads (show other bugs)
Version: 14.1-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-threads (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-11-16 12:03 UTC by Paul Floyd
Modified: 2024-11-16 12:03 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Floyd 2024-11-16 12:03:12 UTC
This example contains one genuine thread hazard.

#include <future>
#include <iostream>

int main()
{
    char counter = 0;

    auto future1 = std::async(std::launch::async, [&]()
    {
      counter++;
    });
    auto future2 = std::async(std::launch::async, [&]()
    {
      return counter;
    });

    future1.wait();

    // Cast to int to print it as a numerical value rather than a character
    std::cout << (int)future2.get();
}

(just "clang++ -g -o test test.cpp -pthread" to build it).

As well as the genuine error I also get

WARNING: ThreadSanitizer: data race (pid=77285)
  Write of size 8 at 0x000803b17008 by thread T2:
    #0 memset /usr/src/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc:87:3 (test1+0x27a626)
    #1 __crt_calloc /usr/src/libexec/rtld-elf/rtld_malloc.c:168:3 (libthr.so.3+0x1e4f6)
    #2 std::__1::__thread_specific_ptr<std::__1::__thread_struct>::set_pointer(std::__1::__thread_struct*) /usr/include/c++/v1/__thread/thread.h:111:3 (bt1+0x2dd3b4)
    #3 void* std::__1::__thread_proxy[abi:se180100]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (std::__1::__async_assoc_state<char, std::__1::__async_func<main::$_1>>::*)(), std::__1::__async_assoc_state<char, std::__1::__async_func<main::$_1>>*>>(void*) /usr/include/c++/v1/__thread/thread.h:200:25 (bt1+0x2db9bc)

  Previous write of size 8 at 0x000803b17008 by thread T1:
    #0 memset /usr/src/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc:87:3 (bt1+0x27a626)
    #1 __crt_calloc /usr/src/libexec/rtld-elf/rtld_malloc.c:168:3 (libthr.so.3+0x1e4f6)
    #2 std::__1::__thread_specific_ptr<std::__1::__thread_struct>::set_pointer(std::__1::__thread_struct*) /usr/include/c++/v1/__thread/thread.h:111:3 (bt1+0x2dd3b4)
    #3 void* std::__1::__thread_proxy[abi:se180100]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_0>>::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_0>>*>>(void*) /usr/include/c++/v1/__thread/thread.h:200:25 (bt1+0x2d9d4c)

This looks like something during thread startup.

On Linux I only get the one genuine error.