File tree 3 files changed +20
-12
lines changed
3 files changed +20
-12
lines changed Original file line number Diff line number Diff line change @@ -51,13 +51,12 @@ redirects output to the corresponding Python streams:
51
51
52
52
The implementation in ``pybind11/iostream.h `` is NOT thread safe. Multiple
53
53
threads writing to a redirected ostream concurrently cause data races
54
- and potentially buffer overflows. Therefore it is a requirement that
55
- all (possibly) concurrent redirected ostream writes are locked. Note
56
- that this is not expected to be an actual limitation, because without
57
- synchronization output will be randomly interleaved and most likely
58
- unreadable. Well-written C++ code is likely to use locking regardless of
59
- this pybind11 requirement. — For more background see the discussion under
60
- `PR #2982 <https://github.com/pybind/pybind11/pull/2982 >`_.
54
+ and potentially buffer overflows. Therefore it is currrently a requirement
55
+ that all (possibly) concurrent redirected ostream writes are protected by
56
+ a mutex. #HelpAppreciated: Work on iostream.h thread safety. For more
57
+ background see the discussions under
58
+ `PR #2982 <https://github.com/pybind/pybind11/pull/2982 >`_ and
59
+ `PR #2995 <https://github.com/pybind/pybind11/pull/2995 >`_.
61
60
62
61
This method respects flushes on the output streams and will flush if needed
63
62
when the scoped guard is destroyed. This allows the output to be redirected in
Original file line number Diff line number Diff line change 7
7
BSD-style license that can be found in the LICENSE file.
8
8
9
9
WARNING: The implementation in this file is NOT thread safe. Multiple
10
- threads writing to a redirected ostream concurrently cause data races and
11
- potentially buffer overflows. Therefore it is a REQUIREMENT that all
12
- (possibly) concurrent redirected ostream writes are locked. For more
13
- background see the discussion under
14
- https://github.com/pybind/pybind11/pull/2982.
10
+ threads writing to a redirected ostream concurrently cause data races
11
+ and potentially buffer overflows. Therefore it is currrently a requirement
12
+ that all (possibly) concurrent redirected ostream writes are protected by
13
+ a mutex.
14
+ #HelpAppreciated: Work on iostream.h thread safety.
15
+ For more background see the discussions under
16
+ https://github.com/pybind/pybind11/pull/2982 and
17
+ https://github.com/pybind/pybind11/pull/2995.
15
18
*/
16
19
17
20
#pragma once
Original file line number Diff line number Diff line change @@ -41,6 +41,12 @@ struct TestThread {
41
41
static std::mutex cout_mutex;
42
42
while (!stop_) {
43
43
{
44
+ // #HelpAppreciated: Work on iostream.h thread safety.
45
+ // Without this lock, the clang ThreadSanitizer (tsan) reliably reports a
46
+ // data race, and this test is predictably flakey on Windows.
47
+ // For more background see the discussion under
48
+ // https://github.com/pybind/pybind11/pull/2982 and
49
+ // https://github.com/pybind/pybind11/pull/2995.
44
50
const std::lock_guard<std::mutex> lock (cout_mutex);
45
51
std::cout << " x" << std::flush;
46
52
}
You can’t perform that action at this time.
0 commit comments