MCPcopy Create free account
hub / github.com/pybind/pybind11 / TestThread

Method TestThread

tests/test_iostream.cpp:37–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35// redirect is called at some point to test the safety of scoped_estream_redirect
36struct TestThread {
37 TestThread() : stop_{false} {
38 auto thread_f = [this] {
39 static std::mutex cout_mutex;
40 while (!stop_) {
41 {
42 // #HelpAppreciated: Work on iostream.h thread safety.
43 // Without this lock, the clang ThreadSanitizer (tsan) reliably reports a
44 // data race, and this test is predictably flakey on Windows.
45 // For more background see the discussion under
46 // https://github.com/pybind/pybind11/pull/2982 and
47 // https://github.com/pybind/pybind11/pull/2995.
48 const std::lock_guard<std::mutex> lock(cout_mutex);
49 std::cout << "x" << std::flush;
50 }
51 std::this_thread::sleep_for(std::chrono::microseconds(50));
52 }
53 };
54 t_ = new std::thread(std::move(thread_f));
55 }
56
57 ~TestThread() { delete t_; }
58

Callers 1

test_threadingFunction · 0.80

Calls 1

moveFunction · 0.85

Tested by

no test coverage detected