From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id C4CEC383583E; Wed, 22 Jun 2022 05:22:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C4CEC383583E 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: 9ed71d6e0d61623bbc1f18694946323230b6531e X-Git-Newrev: 82ea4c64c40b950d38b3808412627cf91f7f67b8 Message-Id: <20220622052249.C4CEC383583E@sourceware.org> Date: Wed, 22 Jun 2022 05:22:49 +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: Wed, 22 Jun 2022 05:22:49 -0000 https://gcc.gnu.org/g:82ea4c64c40b950d38b3808412627cf91f7f67b8 commit 82ea4c64c40b950d38b3808412627cf91f7f67b8 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()