-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding iostream.h thread-safety documentation. #2995
Adding iostream.h thread-safety documentation. #2995
Conversation
Remove a test because it triggers a failure? Why not just follow the docs you are adding in literally the same PR and add a lock to the test? At least that would illustrate and test the docs you've just written. |
That's what I tried first. Pieter replied with a "defeats the point of the test" comment here: #2982 (comment) Basically, it would make that part of the unit test just a demo for how to do locking. I think it's better removed. |
Can we just disable the test for Windows? We've never seen it flake on anything but MSVC. |
Thanks Henry, we could, but
Two-and-a-half ideas:
Please let me know what you prefer and I'll change this PR accordingly. |
My preference would be for idea 2 (test with mutexes) - I'm not that worried about stdlib includes in a test file, and it makes it a really nice example (if it works). But other than that, given the two points you listed, the current form of the PR is acceptable if not quite as ideal as that would be. |
Thanks Henry, I'll restore |
The changes to the documentation look good to me. Maybe I would be more specific about this sentence:
Perhaps “protected using a mutex” is clearer than “locked”? I agree that it might be a good idea to keep a multithreaded test as an example on how to do the locking correctly. In that case I would try to isolate it from the other iostream tests, i.e. don't add locks to the existing functions I've thought about it some more, and locking in user code could prove problematic:
The following sequence now causes deadlock:
Keeping this in mind, adding the locking to |
Hi All, please take another look. The When I started this PR, my main interest was to get rid of the test_iostream Windows flakiness and the TSAN error. I don't have a vested interest beyond those two points. Currently, iostream.h is not used at Google. The TSAN error is definitely gone, I ran the test 1000 times. I assume the Windows flakiness is also gone, although we may have to wait and see to be sure. |
Small update, the Windows flake still happens, although much more rarely after #2982 was merged. Here is one example I just observed: https://github.com/pybind/pybind11/pull/3023/checks?check_run_id=2743130279 |
Here is another one, different Python version (3.8 vs 2.7), different C++ standard (11 vs. 17), but same symptom: https://github.com/pybind/pybind11/pull/3030/checks?check_run_id=2758466712 |
I just hit on this again, after not seeing these errors for quite a long time:
This was with ASAN (not TSAN). @henryiii I feel we really need to warn users prominently. |
e533a17
to
307f8a8
Compare
Thanks Henry! |
…ell check was added after the CI for PR pybind#2995 last ran.
Description
For full background see the discussions under PR #2982 and this PR.
This PR resolves the clang ThreadSanitizer (tsan) error reported under #2754, but only in stop-gap fashion.
#HelpAppreciated: Work on iostream.h thread safety.
Suggested changelog entry: