Skip to content

Commit 830beda

Browse files
VS 2019 16.8 Preview 4, Python 3.9.0, absolute time fix (#1371)
Co-authored-by: Casey Carter <cacarter@microsoft.com>
1 parent e7d5113 commit 830beda

File tree

9 files changed

+35
-17
lines changed

9 files changed

+35
-17
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Just try to follow these rules, so we can spend more time fixing bugs and implem
143143
The STL uses boost-math headers to provide P0226R1 Mathematical Special Functions. We recommend using [vcpkg][] to
144144
acquire this dependency.
145145

146-
1. Install Visual Studio 2019 16.8 Preview 3 or later.
146+
1. Install Visual Studio 2019 16.8 Preview 4 or later.
147147
* We recommend selecting "C++ CMake tools for Windows" in the VS Installer.
148148
This will ensure that you're using supported versions of CMake and Ninja.
149149
* Otherwise, install [CMake][] 3.17 or later, and [Ninja][] 1.8.2 or later.
@@ -158,7 +158,7 @@ acquire this dependency.
158158

159159
# How To Build With A Native Tools Command Prompt
160160

161-
1. Install Visual Studio 2019 16.8 Preview 3 or later.
161+
1. Install Visual Studio 2019 16.8 Preview 4 or later.
162162
* We recommend selecting "C++ CMake tools for Windows" in the VS Installer.
163163
This will ensure that you're using supported versions of CMake and Ninja.
164164
* Otherwise, install [CMake][] 3.17 or later, and [Ninja][] 1.8.2 or later.
@@ -235,7 +235,7 @@ C:\Users\username\Desktop>dumpbin /IMPORTS .\example.exe | findstr msvcp
235235

236236
1. Follow either [How To Build With A Native Tools Command Prompt][] or [How To Build With The Visual Studio IDE][].
237237
2. Invoke `git submodule update --init llvm-project` at the root of the STL source tree.
238-
3. Acquire [Python][] 3.8 or newer and have it on the `PATH` (or run it directly using its absolute or relative path).
238+
3. Acquire [Python][] 3.9 or newer and have it on the `PATH` (or run it directly using its absolute or relative path).
239239
4. Have LLVM's `bin` directory on the `PATH` (so `clang-cl.exe` is available).
240240
* We recommend selecting "C++ Clang tools for Windows" in the VS Installer. This will automatically add LLVM to the
241241
`PATH` of the x86 and x64 Native Tools Command Prompts, and will ensure that you're using a supported version.

azure-devops/provision-image.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ $Workloads = @(
9797
$ReleaseInPath = 'Preview'
9898
$Sku = 'Enterprise'
9999
$VisualStudioBootstrapperUrl = 'https://aka.ms/vs/16/pre/vs_enterprise.exe'
100-
$PythonUrl = 'https://www.python.org/ftp/python/3.8.5/python-3.8.5-amd64.exe'
100+
$PythonUrl = 'https://www.python.org/ftp/python/3.9.0/python-3.9.0-amd64.exe'
101101

102102
$CudaUrl = `
103103
'https://developer.download.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda_10.1.243_426.00_win10.exe'

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
variables:
77
tmpDir: 'D:\Temp'
88

9-
pool: 'StlBuild-2020-09-14'
9+
pool: 'StlBuild-2020-10-13'
1010

1111
stages:
1212
- stage: Code_Format

stl/inc/condition_variable

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public:
130130
template <class _Lock, class _Rep, class _Period, class _Predicate>
131131
bool wait_for(_Lock& _Lck, const chrono::duration<_Rep, _Period>& _Rel_time, _Predicate _Pred) {
132132
// wait for signal with timeout and check predicate
133-
return wait_until(_Lck, chrono::steady_clock::now() + _Rel_time, _STD move(_Pred));
133+
return wait_until(_Lck, _To_absolute_time(_Rel_time), _STD move(_Pred));
134134
}
135135

136136
template <class _Lock>
@@ -232,7 +232,7 @@ public:
232232

233233
template <class _Lock, class _Rep, class _Period, class _Predicate>
234234
bool wait_for(_Lock& _Lck, stop_token _Stoken, const chrono::duration<_Rep, _Period>& _Rel_time, _Predicate _Pred) {
235-
return wait_until(_Lck, _STD move(_Stoken), chrono::steady_clock::now() + _Rel_time, _STD move(_Pred));
235+
return wait_until(_Lck, _STD move(_Stoken), _To_absolute_time(_Rel_time), _STD move(_Pred));
236236
}
237237
#endif // _HAS_CXX20
238238

stl/inc/mutex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ public:
628628
template <class _Rep, class _Period, class _Predicate>
629629
bool wait_for(unique_lock<mutex>& _Lck, const chrono::duration<_Rep, _Period>& _Rel_time, _Predicate _Pred) {
630630
// wait for signal with timeout and check predicate
631-
return _Wait_until1(_Lck, chrono::steady_clock::now() + _Rel_time, _Pred);
631+
return _Wait_until1(_Lck, _To_absolute_time(_Rel_time), _Pred);
632632
}
633633

634634
template <class _Clock, class _Duration>
@@ -776,7 +776,7 @@ public:
776776

777777
template <class _Rep, class _Period>
778778
_NODISCARD bool try_lock_for(const chrono::duration<_Rep, _Period>& _Rel_time) { // try to lock for duration
779-
return try_lock_until(chrono::steady_clock::now() + _Rel_time);
779+
return try_lock_until(_To_absolute_time(_Rel_time));
780780
}
781781

782782
template <class _Time>
@@ -875,7 +875,7 @@ public:
875875

876876
template <class _Rep, class _Period>
877877
_NODISCARD bool try_lock_for(const chrono::duration<_Rep, _Period>& _Rel_time) { // try to lock for duration
878-
return try_lock_until(chrono::steady_clock::now() + _Rel_time);
878+
return try_lock_until(_To_absolute_time(_Rel_time));
879879
}
880880

881881
template <class _Time>

stl/inc/shared_mutex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public:
110110

111111
template <class _Rep, class _Period>
112112
_NODISCARD bool try_lock_for(const chrono::duration<_Rep, _Period>& _Rel_time) { // try to lock for duration
113-
return try_lock_until(chrono::steady_clock::now() + _Rel_time);
113+
return try_lock_until(_To_absolute_time(_Rel_time));
114114
}
115115

116116
template <class _Clock, class _Duration>
@@ -168,7 +168,7 @@ public:
168168
template <class _Rep, class _Period>
169169
_NODISCARD bool try_lock_shared_for(
170170
const chrono::duration<_Rep, _Period>& _Rel_time) { // try to lock non-exclusive for relative time
171-
return try_lock_shared_until(_Rel_time + chrono::steady_clock::now());
171+
return try_lock_shared_until(_To_absolute_time(_Rel_time));
172172
}
173173

174174
template <class _Time>

stl/inc/thread

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,22 @@ private:
156156
_Thrd_t _Thr;
157157
};
158158

159+
template <class _Rep, class _Period>
160+
_NODISCARD auto _To_absolute_time(const chrono::duration<_Rep, _Period>& _Rel_time) noexcept {
161+
constexpr auto _Zero = chrono::duration<_Rep, _Period>::zero();
162+
const auto _Now = chrono::steady_clock::now();
163+
decltype(_Now + _Rel_time) _Abs_time = _Now; // return common type
164+
if (_Rel_time > _Zero) {
165+
constexpr auto _Forever = (chrono::steady_clock::time_point::max)();
166+
if (_Abs_time < _Forever - _Rel_time) {
167+
_Abs_time += _Rel_time;
168+
} else {
169+
_Abs_time = _Forever;
170+
}
171+
}
172+
return _Abs_time;
173+
}
174+
159175
namespace this_thread {
160176
_NODISCARD thread::id get_id() noexcept;
161177

@@ -183,7 +199,7 @@ namespace this_thread {
183199

184200
template <class _Rep, class _Period>
185201
void sleep_for(const chrono::duration<_Rep, _Period>& _Rel_time) {
186-
sleep_until(chrono::steady_clock::now() + _Rel_time);
202+
sleep_until(_To_absolute_time(_Rel_time));
187203
}
188204
} // namespace this_thread
189205

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ add_subdirectory(tr1)
1818
# chance to add to the config map and test directory global properties.
1919
add_subdirectory(utils/stl-lit)
2020

21-
find_package(Python "3.8" REQUIRED COMPONENTS Interpreter)
21+
find_package(Python "3.9" REQUIRED COMPONENTS Interpreter)
2222

2323
if(NOT DEFINED LIT_FLAGS)
2424
list(APPEND LIT_FLAGS "-o" "${CMAKE_CURRENT_BINARY_DIR}/test_results.json")

tests/std/tests/P0660R10_jthread_and_cv_any/test.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ int main() {
180180
jthread worker([&](stop_token token) {
181181
unique_lock lck{m};
182182
assert(cv.wait(lck, move(token), [] { return true; }) == true);
183-
assert(cv.wait(lck, move(token), [&] { return b; }) == true);
183+
assert(cv.wait(lck, move(token), [&] { return b; }) == true); // Intentionally uses moved-from token
184184
});
185185

186186
{
@@ -198,7 +198,8 @@ int main() {
198198
jthread worker([&](stop_token token) {
199199
unique_lock lck{m};
200200
assert(cv.wait_until(lck, move(token), infinity, [] { return true; }) == true);
201-
assert(cv.wait_until(lck, move(token), infinity, [&] { return b; }) == true);
201+
assert(cv.wait_until(lck, move(token), infinity, [&] { return b; })
202+
== true); // Intentionally uses moved-from token
202203
});
203204

204205
{
@@ -216,7 +217,8 @@ int main() {
216217
jthread worker([&](stop_token token) {
217218
unique_lock lck{m};
218219
assert(cv.wait_for(lck, move(token), forever, [] { return true; }) == true);
219-
assert(cv.wait_for(lck, move(token), forever, [&] { return b; }) == true);
220+
assert(cv.wait_for(lck, move(token), forever, [&] { return b; })
221+
== true); // Intentionally uses moved-from token
220222
});
221223

222224
{

0 commit comments

Comments
 (0)