Skip to content

Conversation

@vmichal
Copy link

@vmichal vmichal commented Nov 20, 2025

Change pass-by-const-reference to pass-by-value.
Add tests.

Fixes #5859.

@vmichal vmichal requested a review from a team as a code owner November 20, 2025 00:57
@github-project-automation github-project-automation bot moved this to Initial Review in STL Code Reviews Nov 20, 2025
@vmichal
Copy link
Author

vmichal commented Nov 20, 2025

Notes and questions for review:

The behavior of most overloads stays identical, as they are all implemented in terms of other functions from the wait_{for, until} family, just with relative time converted to absolute or vice versa. In such cases, const & was bound to temporary objects and thus possible modifications by the user were ignored. For this reason, some changes are not testable; however, I have provided the tests for completeness.

I have kept all absolute/relative timeouts as const arguments. It appears that some parts of the STL adhere to the "const everything" guideline, so I hope it is valid.

While preparing the tests, I have found a difference in the behavior of MSVC and clang/GCC. Details are in #5859 (comment)

@StephanTLavavej StephanTLavavej added the LWG Library Working Group issue label Nov 20, 2025
@StephanTLavavej StephanTLavavej moved this from Initial Review to Work In Progress in STL Code Reviews Nov 20, 2025
@StephanTLavavej
Copy link
Member

Moving to WIP as there are test failures.

@vmichal
Copy link
Author

vmichal commented Nov 20, 2025

I have incorporated @frederick-vs-ja 's suggestions. However, regarding the failing tests, I am baffled a little. I can't reliably reproduce the failure - I reproduced it twice using stl-lit, but never with debugger attached.
I will try to dig deeper into it, but should anyone find a problem, I'd be most grateful.

@StephanTLavavej
Copy link
Member

Are there timing assumptions in your tests? Whenever exercising timeout-related code, we need to be very careful to write tests such that they always succeed, regardless of how quickly or slowly operations complete, limited only by the Standard's guarantees. We've had to fix/skip a lot of tests containing assumptions like "surely this will complete in 100ms" or "surely this will never take 2 seconds".

@AlexGuteniev
Copy link
Contributor

Are there timing assumptions in your tests?

It is GH_000685_condition_variable_any test that fails:

  std :: tests/GH_000685_condition_variable_any:12
  std :: tests/GH_000685_condition_variable_any:29

It doesn't seem to have any timing assumptions.
Maybe no-spurious-unblock assumption though, the test might have it.

@vmichal
Copy link
Author

vmichal commented Nov 21, 2025

Are there timing assumptions in your tests? Whenever exercising timeout-related code, we need to be very careful to write tests such that they always succeed, regardless of how quickly or slowly operations complete, limited only by the Standard's guarantees. We've had to fix/skip a lot of tests containing assumptions like "surely this will complete in 100ms" or "surely this will never take 2 seconds".

I have sprinkled the test with some assertions and I have pinpointed the issue - exactly as you suggested. I assumed the child thread is fired in less than 100 ms, whereas in reality, I have observed some very high delays (e.g. 5 seconds). I will add some startup synchronization to ensure the child thread is properly started; it is not very elegant in C++11 (without std::latch) though...

@StephanTLavavej StephanTLavavej moved this from Work In Progress to Initial Review in STL Code Reviews Nov 23, 2025
// If the main thread wait times out after short time, the modification did not influence the ongoing wait
template <typename CV>
void test_timeout_immutable(int test_number, int retries_remaining = 5) {
printf("\ntest %d\n", test_number);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to include <cstdio>. I suppose these printfs are an acceptable exception to our usual conventions.

Copy link
Author

@vmichal vmichal Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They were very valuable when collecting test results, but I don't have strong feeling for them. I meant to remove them before pushing, but apparently I did not. If you say so, I can remove them. Especially when you suggest that usage of printf in tests is rare.

@StephanTLavavej StephanTLavavej moved this from Initial Review to Ready To Merge in STL Code Reviews Nov 24, 2025
@StephanTLavavej StephanTLavavej moved this from Ready To Merge to Merging in STL Code Reviews Nov 25, 2025
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LWG Library Working Group issue

Projects

Status: Merging

Development

Successfully merging this pull request may close these issues.

LWG-4301 condition_variable{_any}::wait_{for, until} should take timeout by value

4 participants