| 35 | // redirect is called at some point to test the safety of scoped_estream_redirect |
| 36 | struct 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 |
no test coverage detected