Skip to content

Instantly share code, notes, and snippets.

@Verdagon
Created November 29, 2025 03:45
Show Gist options
  • Select an option

  • Save Verdagon/6fb618b3a01e932dd4a42ac77e252606 to your computer and use it in GitHub Desktop.

Select an option

Save Verdagon/6fb618b3a01e932dd4a42ac77e252606 to your computer and use it in GitHub Desktop.
#include <memory>
#include <thread>
struct Engine {
int fuel = 100;
};
struct Spaceship {
std::shared_ptr<Engine> engine = std::make_shared<Engine>();
};
void accelerate(std::shared_ptr<Spaceship> ship) {
std::shared_ptr<Engine> engine = ship->engine;
}
void replaceEngine(std::shared_ptr<Spaceship> ship) {
ship->engine = std::make_shared<Engine>();
}
int main() {
auto ship = std::make_shared<Spaceship>();
std::thread t1([&]() {
for (int i = 0; i < 1000000; i++)
accelerate(ship);
});
std::thread t2([&]() {
for (int i = 0; i < 1000000; i++)
replaceEngine(ship);
});
t1.join();
t2.join();
return 0;
}
// verdagon@Evans-MacBook-Pro cppub % clang++ -std=c++17 -pthread -g -fsanitize=thread main.cpp && ./a.out
// a.out(14608,0x1fd2d7ac0) malloc: nano zone abandoned due to inability to reserve vm space.
// ==================
// WARNING: ThreadSanitizer: data race (pid=14608)
// Write of size 8 at 0x000106c008b8 by thread T2:
// #0 std::__1::enable_if<is_move_constructible<Engine*>::value && is_move_assignable<Engine*>::value, void>::type std::__1::swap[abi:ue170006]<Engine*>(Engine*&, Engine*&) swap.h:44 (a.out:arm64+0x100004c14)
// #1 std::__1::shared_ptr<Engine>::swap[abi:ue170006](std::__1::shared_ptr<Engine>&) shared_ptr.h:833 (a.out:arm64+0x100004a7c)
// #2 std::__1::shared_ptr<Engine>::operator=[abi:ue170006](std::__1::shared_ptr<Engine>&&) shared_ptr.h:794 (a.out:arm64+0x100002d50)
// #3 replaceEngine(std::__1::shared_ptr<Spaceship>) main.cpp:17 (a.out:arm64+0x100002c6c)
// #4 main::$_1::operator()() const main.cpp:31 (a.out:arm64+0x100008190)
// #5 decltype(std::declval<main::$_1>()()) std::__1::__invoke[abi:ue170006]<main::$_1>(main::$_1&&) invoke.h:340 (a.out:arm64+0x1000080a4)
// #6 _ZNSt3__116__thread_executeB8ue170006INS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEZ4mainE3$_1JETpTnmJEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE thread.h:227 (a.out:arm64+0x10000804c)
// #7 void* std::__1::__thread_proxy[abi:ue170006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, main::$_1>>(void*) thread.h:238 (a.out:arm64+0x100007aac)
//
// Previous read of size 8 at 0x000106c008b8 by thread T1:
// #0 std::__1::shared_ptr<Engine>::shared_ptr[abi:ue170006](std::__1::shared_ptr<Engine> const&) shared_ptr.h:662 (a.out:arm64+0x100003074)
// #1 std::__1::shared_ptr<Engine>::shared_ptr[abi:ue170006](std::__1::shared_ptr<Engine> const&) shared_ptr.h:664 (a.out:arm64+0x100002bc0)
// #2 accelerate(std::__1::shared_ptr<Spaceship>) main.cpp:13 (a.out:arm64+0x100002b08)
// #3 main::$_0::operator()() const main.cpp:25 (a.out:arm64+0x1000070d0)
// #4 decltype(std::declval<main::$_0>()()) std::__1::__invoke[abi:ue170006]<main::$_0>(main::$_0&&) invoke.h:340 (a.out:arm64+0x100006ff8)
// #5 _ZNSt3__116__thread_executeB8ue170006INS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEZ4mainE3$_0JETpTnmJEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE thread.h:227 (a.out:arm64+0x100006f1c)
// #6 void* std::__1::__thread_proxy[abi:ue170006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, main::$_0>>(void*) thread.h:238 (a.out:arm64+0x10000625c)
//
// Location is heap block of size 40 at 0x000106c008a0 allocated by main thread:
// #0 operator new(unsigned long) <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64+0x85ad8)
// #1 void* std::__1::__libcpp_operator_new[abi:ue170006]<unsigned long>(unsigned long) new:298 (a.out:arm64+0x100003d78)
// #2 std::__1::__libcpp_allocate[abi:ue170006](unsigned long, unsigned long) new:324 (a.out:arm64+0x100003c64)
// #3 std::__1::allocator<std::__1::__shared_ptr_emplace<Spaceship, std::__1::allocator<Spaceship>>>::allocate[abi:ue170006](unsigned long) allocator.h:114 (a.out:arm64+0x1000053ec)
// #4 std::__1::allocator_traits<std::__1::allocator<std::__1::__shared_ptr_emplace<Spaceship, std::__1::allocator<Spaceship>>>>::allocate[abi:ue170006](std::__1::allocator<std::__1::__shared_ptr_emplace<Spaceship, std::__1::allocator<Spaceship>>>&, unsigned long) allocator_traits.h:268 (a.out:arm64+0x1000052dc)
// #5 std::__1::__allocation_guard<std::__1::allocator<std::__1::__shared_ptr_emplace<Spaceship, std::__1::allocator<Spaceship>>>>::__allocation_guard[abi:ue170006]<std::__1::allocator<Spaceship>>(std::__1::allocator<Spaceship>, unsigned long) allocation_guard.h:57 (a.out:arm64+0x1000051f8)
// #6 std::__1::__allocation_guard<std::__1::allocator<std::__1::__shared_ptr_emplace<Spaceship, std::__1::allocator<Spaceship>>>>::__allocation_guard[abi:ue170006]<std::__1::allocator<Spaceship>>(std::__1::allocator<Spaceship>, unsigned long) allocation_guard.h:58 (a.out:arm64+0x100004e84)
// #7 std::__1::shared_ptr<Spaceship> std::__1::allocate_shared[abi:ue170006]<Spaceship, std::__1::allocator<Spaceship>, void>(std::__1::allocator<Spaceship> const&) shared_ptr.h:1022 (a.out:arm64+0x100004d34)
// #8 std::__1::shared_ptr<Spaceship> std::__1::make_shared[abi:ue170006]<Spaceship, void>() shared_ptr.h:1032 (a.out:arm64+0x100002ed4)
// #9 main main.cpp:21 (a.out:arm64+0x100002d90)
//
// Thread T2 (tid=461113, running) created by main thread at:
// #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64+0x31764)
// #1 std::__1::__libcpp_thread_create[abi:ue170006](_opaque_pthread_t**, void* (*)(void*), void*) __threading_support:371 (a.out:arm64+0x1000061c0)
// #2 std::__1::thread::thread<main::$_1, void>(main::$_1&&) thread.h:254 (a.out:arm64+0x100007888)
// #3 std::__1::thread::thread<main::$_1, void>(main::$_1&&) thread.h:246 (a.out:arm64+0x100002fb0)
// #4 main main.cpp:29 (a.out:arm64+0x100002dc0)
//
// Thread T1 (tid=461112, running) created by main thread at:
// #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64+0x31764)
// #1 std::__1::__libcpp_thread_create[abi:ue170006](_opaque_pthread_t**, void* (*)(void*), void*) __threading_support:371 (a.out:arm64+0x1000061c0)
// #2 std::__1::thread::thread<main::$_0, void>(main::$_0&&) thread.h:254 (a.out:arm64+0x100005f58)
// #3 std::__1::thread::thread<main::$_0, void>(main::$_0&&) thread.h:246 (a.out:arm64+0x100002f40)
// #4 main main.cpp:23 (a.out:arm64+0x100002da8)
//
// SUMMARY: ThreadSanitizer: data race swap.h:44 in std::__1::enable_if<is_move_constructible<Engine*>::value && is_move_assignable<Engine*>::value, void>::type std::__1::swap[abi:ue170006]<Engine*>(Engine*&, Engine*&)
// ==================
// ==================
// WARNING: ThreadSanitizer: data race (pid=14608)
// Write of size 8 at 0x000106c008c0 by thread T2:
// #0 std::__1::enable_if<is_move_constructible<std::__1::__shared_weak_count*>::value && is_move_assignable<std::__1::__shared_weak_count*>::value, void>::type std::__1::swap[abi:ue170006]<std::__1::__shared_weak_count*>(std::__1::__shared_weak_count*&, std::__1::__shared_weak_count*&) swap.h:44 (a.out:arm64+0x100004cc4)
// #1 std::__1::shared_ptr<Engine>::swap[abi:ue170006](std::__1::shared_ptr<Engine>&) shared_ptr.h:834 (a.out:arm64+0x100004a90)
// #2 std::__1::shared_ptr<Engine>::operator=[abi:ue170006](std::__1::shared_ptr<Engine>&&) shared_ptr.h:794 (a.out:arm64+0x100002d50)
// #3 replaceEngine(std::__1::shared_ptr<Spaceship>) main.cpp:17 (a.out:arm64+0x100002c6c)
// #4 main::$_1::operator()() const main.cpp:31 (a.out:arm64+0x100008190)
// #5 decltype(std::declval<main::$_1>()()) std::__1::__invoke[abi:ue170006]<main::$_1>(main::$_1&&) invoke.h:340 (a.out:arm64+0x1000080a4)
// #6 _ZNSt3__116__thread_executeB8ue170006INS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEZ4mainE3$_1JETpTnmJEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE thread.h:227 (a.out:arm64+0x10000804c)
// #7 void* std::__1::__thread_proxy[abi:ue170006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, main::$_1>>(void*) thread.h:238 (a.out:arm64+0x100007aac)
//
// Previous read of size 8 at 0x000106c008c0 by thread T1:
// #0 std::__1::shared_ptr<Engine>::shared_ptr[abi:ue170006](std::__1::shared_ptr<Engine> const&) shared_ptr.h:663 (a.out:arm64+0x1000030a4)
// #1 std::__1::shared_ptr<Engine>::shared_ptr[abi:ue170006](std::__1::shared_ptr<Engine> const&) shared_ptr.h:664 (a.out:arm64+0x100002bc0)
// #2 accelerate(std::__1::shared_ptr<Spaceship>) main.cpp:13 (a.out:arm64+0x100002b08)
// #3 main::$_0::operator()() const main.cpp:25 (a.out:arm64+0x1000070d0)
// #4 decltype(std::declval<main::$_0>()()) std::__1::__invoke[abi:ue170006]<main::$_0>(main::$_0&&) invoke.h:340 (a.out:arm64+0x100006ff8)
// #5 _ZNSt3__116__thread_executeB8ue170006INS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEZ4mainE3$_0JETpTnmJEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE thread.h:227 (a.out:arm64+0x100006f1c)
// #6 void* std::__1::__thread_proxy[abi:ue170006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, main::$_0>>(void*) thread.h:238 (a.out:arm64+0x10000625c)
//
// Location is heap block of size 40 at 0x000106c008a0 allocated by main thread:
// #0 operator new(unsigned long) <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64+0x85ad8)
// #1 void* std::__1::__libcpp_operator_new[abi:ue170006]<unsigned long>(unsigned long) new:298 (a.out:arm64+0x100003d78)
// #2 std::__1::__libcpp_allocate[abi:ue170006](unsigned long, unsigned long) new:324 (a.out:arm64+0x100003c64)
// #3 std::__1::allocator<std::__1::__shared_ptr_emplace<Spaceship, std::__1::allocator<Spaceship>>>::allocate[abi:ue170006](unsigned long) allocator.h:114 (a.out:arm64+0x1000053ec)
// #4 std::__1::allocator_traits<std::__1::allocator<std::__1::__shared_ptr_emplace<Spaceship, std::__1::allocator<Spaceship>>>>::allocate[abi:ue170006](std::__1::allocator<std::__1::__shared_ptr_emplace<Spaceship, std::__1::allocator<Spaceship>>>&, unsigned long) allocator_traits.h:268 (a.out:arm64+0x1000052dc)
// #5 std::__1::__allocation_guard<std::__1::allocator<std::__1::__shared_ptr_emplace<Spaceship, std::__1::allocator<Spaceship>>>>::__allocation_guard[abi:ue170006]<std::__1::allocator<Spaceship>>(std::__1::allocator<Spaceship>, unsigned long) allocation_guard.h:57 (a.out:arm64+0x1000051f8)
// #6 std::__1::__allocation_guard<std::__1::allocator<std::__1::__shared_ptr_emplace<Spaceship, std::__1::allocator<Spaceship>>>>::__allocation_guard[abi:ue170006]<std::__1::allocator<Spaceship>>(std::__1::allocator<Spaceship>, unsigned long) allocation_guard.h:58 (a.out:arm64+0x100004e84)
// #7 std::__1::shared_ptr<Spaceship> std::__1::allocate_shared[abi:ue170006]<Spaceship, std::__1::allocator<Spaceship>, void>(std::__1::allocator<Spaceship> const&) shared_ptr.h:1022 (a.out:arm64+0x100004d34)
// #8 std::__1::shared_ptr<Spaceship> std::__1::make_shared[abi:ue170006]<Spaceship, void>() shared_ptr.h:1032 (a.out:arm64+0x100002ed4)
// #9 main main.cpp:21 (a.out:arm64+0x100002d90)
//
// Thread T2 (tid=461113, running) created by main thread at:
// #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64+0x31764)
// #1 std::__1::__libcpp_thread_create[abi:ue170006](_opaque_pthread_t**, void* (*)(void*), void*) __threading_support:371 (a.out:arm64+0x1000061c0)
// #2 std::__1::thread::thread<main::$_1, void>(main::$_1&&) thread.h:254 (a.out:arm64+0x100007888)
// #3 std::__1::thread::thread<main::$_1, void>(main::$_1&&) thread.h:246 (a.out:arm64+0x100002fb0)
// #4 main main.cpp:29 (a.out:arm64+0x100002dc0)
//
// Thread T1 (tid=461112, running) created by main thread at:
// #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64+0x31764)
// #1 std::__1::__libcpp_thread_create[abi:ue170006](_opaque_pthread_t**, void* (*)(void*), void*) __threading_support:371 (a.out:arm64+0x1000061c0)
// #2 std::__1::thread::thread<main::$_0, void>(main::$_0&&) thread.h:254 (a.out:arm64+0x100005f58)
// #3 std::__1::thread::thread<main::$_0, void>(main::$_0&&) thread.h:246 (a.out:arm64+0x100002f40)
// #4 main main.cpp:23 (a.out:arm64+0x100002da8)
//
// SUMMARY: ThreadSanitizer: data race swap.h:44 in std::__1::enable_if<is_move_constructible<std::__1::__shared_weak_count*>::value && is_move_assignable<std::__1::__shared_weak_count*>::value, void>::type std::__1::swap[abi:ue170006]<std::__1::__shared_weak_count*>(std::__1::__shared_weak_count*&, std::__1::__shared_weak_count*&)
// ==================
// ==================
// WARNING: ThreadSanitizer: data race (pid=14608)
// Atomic write of size 8 at 0x000106a01ee8 by thread T1:
// #0 long std::__1::__libcpp_atomic_refcount_increment[abi:ue170006]<long>(long&) shared_ptr.h:106 (a.out:arm64+0x1000031ec)
// #1 std::__1::__shared_count::__add_shared[abi:ue170006]() shared_ptr.h:168 (a.out:arm64+0x100003194)
// #2 std::__1::__shared_weak_count::__add_shared[abi:ue170006]() shared_ptr.h:206 (a.out:arm64+0x10000314c)
// #3 std::__1::shared_ptr<Engine>::shared_ptr[abi:ue170006](std::__1::shared_ptr<Engine> const&) shared_ptr.h:666 (a.out:arm64+0x1000030f8)
// #4 std::__1::shared_ptr<Engine>::shared_ptr[abi:ue170006](std::__1::shared_ptr<Engine> const&) shared_ptr.h:664 (a.out:arm64+0x100002bc0)
// #5 accelerate(std::__1::shared_ptr<Spaceship>) main.cpp:13 (a.out:arm64+0x100002b08)
// #6 main::$_0::operator()() const main.cpp:25 (a.out:arm64+0x1000070d0)
// #7 decltype(std::declval<main::$_0>()()) std::__1::__invoke[abi:ue170006]<main::$_0>(main::$_0&&) invoke.h:340 (a.out:arm64+0x100006ff8)
// #8 _ZNSt3__116__thread_executeB8ue170006INS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEZ4mainE3$_0JETpTnmJEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE thread.h:227 (a.out:arm64+0x100006f1c)
// #9 void* std::__1::__thread_proxy[abi:ue170006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, main::$_0>>(void*) thread.h:238 (a.out:arm64+0x10000625c)
//
// Previous write of size 8 at 0x000106a01ee8 by thread T2:
// #0 std::__1::__shared_count::__shared_count[abi:ue170006](long) shared_ptr.h:160 (a.out:arm64+0x10000418c)
// #1 std::__1::__shared_weak_count::__shared_weak_count[abi:ue170006](long) shared_ptr.h:193 (a.out:arm64+0x100003ec0)
// #2 std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>::__shared_ptr_emplace[abi:ue170006]<>(std::__1::allocator<Engine>) shared_ptr.h:290 (a.out:arm64+0x100003de0)
// #3 std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>::__shared_ptr_emplace[abi:ue170006]<>(std::__1::allocator<Engine>) shared_ptr.h:292 (a.out:arm64+0x100003674)
// #4 std::__1::shared_ptr<Engine> std::__1::allocate_shared[abi:ue170006]<Engine, std::__1::allocator<Engine>, void>(std::__1::allocator<Engine> const&) shared_ptr.h:1023 (a.out:arm64+0x100003478)
// #5 std::__1::shared_ptr<Engine> std::__1::make_shared[abi:ue170006]<Engine, void>() shared_ptr.h:1032 (a.out:arm64+0x100002cd0)
// #6 replaceEngine(std::__1::shared_ptr<Spaceship>) main.cpp:17 (a.out:arm64+0x100002c54)
// #7 main::$_1::operator()() const main.cpp:31 (a.out:arm64+0x100008190)
// #8 decltype(std::declval<main::$_1>()()) std::__1::__invoke[abi:ue170006]<main::$_1>(main::$_1&&) invoke.h:340 (a.out:arm64+0x1000080a4)
// #9 _ZNSt3__116__thread_executeB8ue170006INS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEZ4mainE3$_1JETpTnmJEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE thread.h:227 (a.out:arm64+0x10000804c)
// #10 void* std::__1::__thread_proxy[abi:ue170006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, main::$_1>>(void*) thread.h:238 (a.out:arm64+0x100007aac)
//
// Location is heap block of size 32 at 0x000106a01ee0 allocated by thread T2:
// #0 operator new(unsigned long) <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64+0x85ad8)
// #1 void* std::__1::__libcpp_operator_new[abi:ue170006]<unsigned long>(unsigned long) new:298 (a.out:arm64+0x100003d78)
// #2 std::__1::__libcpp_allocate[abi:ue170006](unsigned long, unsigned long) new:324 (a.out:arm64+0x100003c64)
// #3 std::__1::allocator<std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>>::allocate[abi:ue170006](unsigned long) allocator.h:114 (a.out:arm64+0x100003b1c)
// #4 std::__1::allocator_traits<std::__1::allocator<std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>>>::allocate[abi:ue170006](std::__1::allocator<std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>>&, unsigned long) allocator_traits.h:268 (a.out:arm64+0x100003a10)
// #5 std::__1::__allocation_guard<std::__1::allocator<std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>>>::__allocation_guard[abi:ue170006]<std::__1::allocator<Engine>>(std::__1::allocator<Engine>, unsigned long) allocation_guard.h:57 (a.out:arm64+0x10000392c)
// #6 std::__1::__allocation_guard<std::__1::allocator<std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>>>::__allocation_guard[abi:ue170006]<std::__1::allocator<Engine>>(std::__1::allocator<Engine>, unsigned long) allocation_guard.h:58 (a.out:arm64+0x1000035b8)
// #7 std::__1::shared_ptr<Engine> std::__1::allocate_shared[abi:ue170006]<Engine, std::__1::allocator<Engine>, void>(std::__1::allocator<Engine> const&) shared_ptr.h:1022 (a.out:arm64+0x100003468)
// #8 std::__1::shared_ptr<Engine> std::__1::make_shared[abi:ue170006]<Engine, void>() shared_ptr.h:1032 (a.out:arm64+0x100002cd0)
// #9 replaceEngine(std::__1::shared_ptr<Spaceship>) main.cpp:17 (a.out:arm64+0x100002c54)
// #10 main::$_1::operator()() const main.cpp:31 (a.out:arm64+0x100008190)
// #11 decltype(std::declval<main::$_1>()()) std::__1::__invoke[abi:ue170006]<main::$_1>(main::$_1&&) invoke.h:340 (a.out:arm64+0x1000080a4)
// #12 _ZNSt3__116__thread_executeB8ue170006INS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEZ4mainE3$_1JETpTnmJEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE thread.h:227 (a.out:arm64+0x10000804c)
// #13 void* std::__1::__thread_proxy[abi:ue170006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, main::$_1>>(void*) thread.h:238 (a.out:arm64+0x100007aac)
//
// Thread T1 (tid=461112, running) created by main thread at:
// #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64+0x31764)
// #1 std::__1::__libcpp_thread_create[abi:ue170006](_opaque_pthread_t**, void* (*)(void*), void*) __threading_support:371 (a.out:arm64+0x1000061c0)
// #2 std::__1::thread::thread<main::$_0, void>(main::$_0&&) thread.h:254 (a.out:arm64+0x100005f58)
// #3 std::__1::thread::thread<main::$_0, void>(main::$_0&&) thread.h:246 (a.out:arm64+0x100002f40)
// #4 main main.cpp:23 (a.out:arm64+0x100002da8)
//
// Thread T2 (tid=461113, running) created by main thread at:
// #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64+0x31764)
// #1 std::__1::__libcpp_thread_create[abi:ue170006](_opaque_pthread_t**, void* (*)(void*), void*) __threading_support:371 (a.out:arm64+0x1000061c0)
// #2 std::__1::thread::thread<main::$_1, void>(main::$_1&&) thread.h:254 (a.out:arm64+0x100007888)
// #3 std::__1::thread::thread<main::$_1, void>(main::$_1&&) thread.h:246 (a.out:arm64+0x100002fb0)
// #4 main main.cpp:29 (a.out:arm64+0x100002dc0)
//
// SUMMARY: ThreadSanitizer: data race shared_ptr.h:106 in long std::__1::__libcpp_atomic_refcount_increment[abi:ue170006]<long>(long&)
// ==================
// ==================
// WARNING: ThreadSanitizer: data race on vptr (ctor/dtor vs virtual call) (pid=14608)
// Read of size 8 at 0x000106a01e80 by thread T1:
// #0 std::__1::__shared_count::__release_shared[abi:ue170006]() shared_ptr.h:173 (a.out:arm64+0x10000334c)
// #1 std::__1::__shared_weak_count::__release_shared[abi:ue170006]() shared_ptr.h:214 (a.out:arm64+0x1000032d8)
// #2 std::__1::shared_ptr<Engine>::~shared_ptr[abi:ue170006]() shared_ptr.h:773 (a.out:arm64+0x100003280)
// #3 std::__1::shared_ptr<Engine>::~shared_ptr[abi:ue170006]() shared_ptr.h:771 (a.out:arm64+0x100002c0c)
// #4 accelerate(std::__1::shared_ptr<Spaceship>) main.cpp:14 (a.out:arm64+0x100002b10)
// #5 main::$_0::operator()() const main.cpp:25 (a.out:arm64+0x1000070d0)
// #6 decltype(std::declval<main::$_0>()()) std::__1::__invoke[abi:ue170006]<main::$_0>(main::$_0&&) invoke.h:340 (a.out:arm64+0x100006ff8)
// #7 _ZNSt3__116__thread_executeB8ue170006INS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEZ4mainE3$_0JETpTnmJEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE thread.h:227 (a.out:arm64+0x100006f1c)
// #8 void* std::__1::__thread_proxy[abi:ue170006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, main::$_0>>(void*) thread.h:238 (a.out:arm64+0x10000625c)
//
// Previous write of size 8 at 0x000106a01e80 by thread T2:
// #0 std::__1::__shared_count::__shared_count[abi:ue170006](long) shared_ptr.h:160 (a.out:arm64+0x100004170)
// #1 std::__1::__shared_weak_count::__shared_weak_count[abi:ue170006](long) shared_ptr.h:193 (a.out:arm64+0x100003ec0)
// #2 std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>::__shared_ptr_emplace[abi:ue170006]<>(std::__1::allocator<Engine>) shared_ptr.h:290 (a.out:arm64+0x100003de0)
// #3 std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>::__shared_ptr_emplace[abi:ue170006]<>(std::__1::allocator<Engine>) shared_ptr.h:292 (a.out:arm64+0x100003674)
// #4 std::__1::shared_ptr<Engine> std::__1::allocate_shared[abi:ue170006]<Engine, std::__1::allocator<Engine>, void>(std::__1::allocator<Engine> const&) shared_ptr.h:1023 (a.out:arm64+0x100003478)
// #5 std::__1::shared_ptr<Engine> std::__1::make_shared[abi:ue170006]<Engine, void>() shared_ptr.h:1032 (a.out:arm64+0x100002cd0)
// #6 replaceEngine(std::__1::shared_ptr<Spaceship>) main.cpp:17 (a.out:arm64+0x100002c54)
// #7 main::$_1::operator()() const main.cpp:31 (a.out:arm64+0x100008190)
// #8 decltype(std::declval<main::$_1>()()) std::__1::__invoke[abi:ue170006]<main::$_1>(main::$_1&&) invoke.h:340 (a.out:arm64+0x1000080a4)
// #9 _ZNSt3__116__thread_executeB8ue170006INS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEZ4mainE3$_1JETpTnmJEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE thread.h:227 (a.out:arm64+0x10000804c)
// #10 void* std::__1::__thread_proxy[abi:ue170006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, main::$_1>>(void*) thread.h:238 (a.out:arm64+0x100007aac)
//
// Location is heap block of size 32 at 0x000106a01e80 allocated by thread T2:
// #0 operator new(unsigned long) <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64+0x85ad8)
// #1 void* std::__1::__libcpp_operator_new[abi:ue170006]<unsigned long>(unsigned long) new:298 (a.out:arm64+0x100003d78)
// #2 std::__1::__libcpp_allocate[abi:ue170006](unsigned long, unsigned long) new:324 (a.out:arm64+0x100003c64)
// #3 std::__1::allocator<std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>>::allocate[abi:ue170006](unsigned long) allocator.h:114 (a.out:arm64+0x100003b1c)
// #4 std::__1::allocator_traits<std::__1::allocator<std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>>>::allocate[abi:ue170006](std::__1::allocator<std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>>&, unsigned long) allocator_traits.h:268 (a.out:arm64+0x100003a10)
// #5 std::__1::__allocation_guard<std::__1::allocator<std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>>>::__allocation_guard[abi:ue170006]<std::__1::allocator<Engine>>(std::__1::allocator<Engine>, unsigned long) allocation_guard.h:57 (a.out:arm64+0x10000392c)
// #6 std::__1::__allocation_guard<std::__1::allocator<std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>>>::__allocation_guard[abi:ue170006]<std::__1::allocator<Engine>>(std::__1::allocator<Engine>, unsigned long) allocation_guard.h:58 (a.out:arm64+0x1000035b8)
// #7 std::__1::shared_ptr<Engine> std::__1::allocate_shared[abi:ue170006]<Engine, std::__1::allocator<Engine>, void>(std::__1::allocator<Engine> const&) shared_ptr.h:1022 (a.out:arm64+0x100003468)
// #8 std::__1::shared_ptr<Engine> std::__1::make_shared[abi:ue170006]<Engine, void>() shared_ptr.h:1032 (a.out:arm64+0x100002cd0)
// #9 replaceEngine(std::__1::shared_ptr<Spaceship>) main.cpp:17 (a.out:arm64+0x100002c54)
// #10 main::$_1::operator()() const main.cpp:31 (a.out:arm64+0x100008190)
// #11 decltype(std::declval<main::$_1>()()) std::__1::__invoke[abi:ue170006]<main::$_1>(main::$_1&&) invoke.h:340 (a.out:arm64+0x1000080a4)
// #12 _ZNSt3__116__thread_executeB8ue170006INS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEZ4mainE3$_1JETpTnmJEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE thread.h:227 (a.out:arm64+0x10000804c)
// #13 void* std::__1::__thread_proxy[abi:ue170006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, main::$_1>>(void*) thread.h:238 (a.out:arm64+0x100007aac)
//
// Thread T1 (tid=461112, running) created by main thread at:
// #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64+0x31764)
// #1 std::__1::__libcpp_thread_create[abi:ue170006](_opaque_pthread_t**, void* (*)(void*), void*) __threading_support:371 (a.out:arm64+0x1000061c0)
// #2 std::__1::thread::thread<main::$_0, void>(main::$_0&&) thread.h:254 (a.out:arm64+0x100005f58)
// #3 std::__1::thread::thread<main::$_0, void>(main::$_0&&) thread.h:246 (a.out:arm64+0x100002f40)
// #4 main main.cpp:23 (a.out:arm64+0x100002da8)
//
// Thread T2 (tid=461113, running) created by main thread at:
// #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64+0x31764)
// #1 std::__1::__libcpp_thread_create[abi:ue170006](_opaque_pthread_t**, void* (*)(void*), void*) __threading_support:371 (a.out:arm64+0x1000061c0)
// #2 std::__1::thread::thread<main::$_1, void>(main::$_1&&) thread.h:254 (a.out:arm64+0x100007888)
// #3 std::__1::thread::thread<main::$_1, void>(main::$_1&&) thread.h:246 (a.out:arm64+0x100002fb0)
// #4 main main.cpp:29 (a.out:arm64+0x100002dc0)
//
// SUMMARY: ThreadSanitizer: data race on vptr (ctor/dtor vs virtual call) shared_ptr.h:173 in std::__1::__shared_count::__release_shared[abi:ue170006]()
// ==================
// ==================
// WARNING: ThreadSanitizer: data race (pid=14608)
// Atomic write of size 8 at 0x000106a021a8 by thread T1:
// #0 long std::__1::__libcpp_atomic_refcount_decrement[abi:ue170006]<long>(long&) shared_ptr.h:117 (a.out:arm64+0x1000033ec)
// #1 std::__1::__shared_count::__release_shared[abi:ue170006]() shared_ptr.h:172 (a.out:arm64+0x100003338)
// #2 std::__1::__shared_weak_count::__release_shared[abi:ue170006]() shared_ptr.h:214 (a.out:arm64+0x1000032d8)
// #3 std::__1::shared_ptr<Engine>::~shared_ptr[abi:ue170006]() shared_ptr.h:773 (a.out:arm64+0x100003280)
// #4 std::__1::shared_ptr<Engine>::~shared_ptr[abi:ue170006]() shared_ptr.h:771 (a.out:arm64+0x100002c0c)
// #5 accelerate(std::__1::shared_ptr<Spaceship>) main.cpp:14 (a.out:arm64+0x100002b10)
// #6 main::$_0::operator()() const main.cpp:25 (a.out:arm64+0x1000070d0)
// #7 decltype(std::declval<main::$_0>()()) std::__1::__invoke[abi:ue170006]<main::$_0>(main::$_0&&) invoke.h:340 (a.out:arm64+0x100006ff8)
// #8 _ZNSt3__116__thread_executeB8ue170006INS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEZ4mainE3$_0JETpTnmJEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE thread.h:227 (a.out:arm64+0x100006f1c)
// #9 void* std::__1::__thread_proxy[abi:ue170006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, main::$_0>>(void*) thread.h:238 (a.out:arm64+0x10000625c)
//
// Previous write of size 8 at 0x000106a021a8 by thread T2:
// #0 std::__1::__shared_count::__shared_count[abi:ue170006](long) shared_ptr.h:160 (a.out:arm64+0x10000418c)
// #1 std::__1::__shared_weak_count::__shared_weak_count[abi:ue170006](long) shared_ptr.h:193 (a.out:arm64+0x100003ec0)
// #2 std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>::__shared_ptr_emplace[abi:ue170006]<>(std::__1::allocator<Engine>) shared_ptr.h:290 (a.out:arm64+0x100003de0)
// #3 std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>::__shared_ptr_emplace[abi:ue170006]<>(std::__1::allocator<Engine>) shared_ptr.h:292 (a.out:arm64+0x100003674)
// #4 std::__1::shared_ptr<Engine> std::__1::allocate_shared[abi:ue170006]<Engine, std::__1::allocator<Engine>, void>(std::__1::allocator<Engine> const&) shared_ptr.h:1023 (a.out:arm64+0x100003478)
// #5 std::__1::shared_ptr<Engine> std::__1::make_shared[abi:ue170006]<Engine, void>() shared_ptr.h:1032 (a.out:arm64+0x100002cd0)
// #6 replaceEngine(std::__1::shared_ptr<Spaceship>) main.cpp:17 (a.out:arm64+0x100002c54)
// #7 main::$_1::operator()() const main.cpp:31 (a.out:arm64+0x100008190)
// #8 decltype(std::declval<main::$_1>()()) std::__1::__invoke[abi:ue170006]<main::$_1>(main::$_1&&) invoke.h:340 (a.out:arm64+0x1000080a4)
// #9 _ZNSt3__116__thread_executeB8ue170006INS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEZ4mainE3$_1JETpTnmJEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE thread.h:227 (a.out:arm64+0x10000804c)
// #10 void* std::__1::__thread_proxy[abi:ue170006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, main::$_1>>(void*) thread.h:238 (a.out:arm64+0x100007aac)
//
// Location is heap block of size 32 at 0x000106a021a0 allocated by thread T2:
// #0 operator new(unsigned long) <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64+0x85ad8)
// #1 void* std::__1::__libcpp_operator_new[abi:ue170006]<unsigned long>(unsigned long) new:298 (a.out:arm64+0x100003d78)
// #2 std::__1::__libcpp_allocate[abi:ue170006](unsigned long, unsigned long) new:324 (a.out:arm64+0x100003c64)
// #3 std::__1::allocator<std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>>::allocate[abi:ue170006](unsigned long) allocator.h:114 (a.out:arm64+0x100003b1c)
// #4 std::__1::allocator_traits<std::__1::allocator<std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>>>::allocate[abi:ue170006](std::__1::allocator<std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>>&, unsigned long) allocator_traits.h:268 (a.out:arm64+0x100003a10)
// #5 std::__1::__allocation_guard<std::__1::allocator<std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>>>::__allocation_guard[abi:ue170006]<std::__1::allocator<Engine>>(std::__1::allocator<Engine>, unsigned long) allocation_guard.h:57 (a.out:arm64+0x10000392c)
// #6 std::__1::__allocation_guard<std::__1::allocator<std::__1::__shared_ptr_emplace<Engine, std::__1::allocator<Engine>>>>::__allocation_guard[abi:ue170006]<std::__1::allocator<Engine>>(std::__1::allocator<Engine>, unsigned long) allocation_guard.h:58 (a.out:arm64+0x1000035b8)
// #7 std::__1::shared_ptr<Engine> std::__1::allocate_shared[abi:ue170006]<Engine, std::__1::allocator<Engine>, void>(std::__1::allocator<Engine> const&) shared_ptr.h:1022 (a.out:arm64+0x100003468)
// #8 std::__1::shared_ptr<Engine> std::__1::make_shared[abi:ue170006]<Engine, void>() shared_ptr.h:1032 (a.out:arm64+0x100002cd0)
// #9 replaceEngine(std::__1::shared_ptr<Spaceship>) main.cpp:17 (a.out:arm64+0x100002c54)
// #10 main::$_1::operator()() const main.cpp:31 (a.out:arm64+0x100008190)
// #11 decltype(std::declval<main::$_1>()()) std::__1::__invoke[abi:ue170006]<main::$_1>(main::$_1&&) invoke.h:340 (a.out:arm64+0x1000080a4)
// #12 _ZNSt3__116__thread_executeB8ue170006INS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEZ4mainE3$_1JETpTnmJEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE thread.h:227 (a.out:arm64+0x10000804c)
// #13 void* std::__1::__thread_proxy[abi:ue170006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, main::$_1>>(void*) thread.h:238 (a.out:arm64+0x100007aac)
//
// Thread T1 (tid=461112, running) created by main thread at:
// #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64+0x31764)
// #1 std::__1::__libcpp_thread_create[abi:ue170006](_opaque_pthread_t**, void* (*)(void*), void*) __threading_support:371 (a.out:arm64+0x1000061c0)
// #2 std::__1::thread::thread<main::$_0, void>(main::$_0&&) thread.h:254 (a.out:arm64+0x100005f58)
// #3 std::__1::thread::thread<main::$_0, void>(main::$_0&&) thread.h:246 (a.out:arm64+0x100002f40)
// #4 main main.cpp:23 (a.out:arm64+0x100002da8)
//
// Thread T2 (tid=461113, running) created by main thread at:
// #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64+0x31764)
// #1 std::__1::__libcpp_thread_create[abi:ue170006](_opaque_pthread_t**, void* (*)(void*), void*) __threading_support:371 (a.out:arm64+0x1000061c0)
// #2 std::__1::thread::thread<main::$_1, void>(main::$_1&&) thread.h:254 (a.out:arm64+0x100007888)
// #3 std::__1::thread::thread<main::$_1, void>(main::$_1&&) thread.h:246 (a.out:arm64+0x100002fb0)
// #4 main main.cpp:29 (a.out:arm64+0x100002dc0)
//
// SUMMARY: ThreadSanitizer: data race shared_ptr.h:117 in long std::__1::__libcpp_atomic_refcount_decrement[abi:ue170006]<long>(long&)
// ==================
// ==14608==FATAL: ThreadSanitizer: internal allocator is out of memory trying to allocate 0x78 bytes
// zsh: abort ./a.out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment