From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id ABEC23841461; Tue, 21 Jun 2022 00:17:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ABEC23841461 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Alexandre Oliva To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc(refs/users/aoliva/heads/testme)] libstdc++: testsuite: tolerate non-cancelling sleep X-Act-Checkin: gcc X-Git-Author: Alexandre Oliva X-Git-Refname: refs/users/aoliva/heads/testme X-Git-Oldrev: 34f7d7035f5398ed85adb55b646af8a0d5c050e9 X-Git-Newrev: 9a35e3acb54f3ca94aebce144802b553d40883e3 Message-Id: <20220621001719.ABEC23841461@sourceware.org> Date: Tue, 21 Jun 2022 00:17:19 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2022 00:17:19 -0000 https://gcc.gnu.org/g:9a35e3acb54f3ca94aebce144802b553d40883e3 commit 9a35e3acb54f3ca94aebce144802b553d40883e3 Author: Alexandre Oliva Date: Mon Jun 20 20:44:07 2022 -0300 libstdc++: testsuite: tolerate non-cancelling sleep Though sleep, nanosleep and clock_nanosleep are all POSIX cancellation points, not all target systems follow this POSIX requirement. 30_threads/thread/native_handle/cancel.cc will run until it times out on such systems. Rather than failing a C++ library test because of a limitation of the target system, this patch gives the test a chance to successfully exercise the features it intends to exercise, by introducing a cancellation point in a loop that would otherwise run indefinitely on systems exhibiting this limitation. for libstdc++-v3/ChangeLog * testsuite/30_threads/thread/native_handle/cancel.cc: Add an explicit cancellation point in case sleep_for lacks one. Diff: --- libstdc++-v3/testsuite/30_threads/thread/native_handle/cancel.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/testsuite/30_threads/thread/native_handle/cancel.cc b/libstdc++-v3/testsuite/30_threads/thread/native_handle/cancel.cc index dca162b3ace..3cef97e8c53 100644 --- a/libstdc++-v3/testsuite/30_threads/thread/native_handle/cancel.cc +++ b/libstdc++-v3/testsuite/30_threads/thread/native_handle/cancel.cc @@ -30,7 +30,11 @@ void f(std::atomic& started) { started = true; while (true) - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + // In case the target system doesn't make sleep a cancellation point... + pthread_testcancel(); + } } int main()