brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · fbc8128 Raw
59 lines · cpp
1// -*- C++ -*-2//===----------------------------------------------------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10// REQUIRES: linux && target=aarch64-{{.+}}-gnu11 12// pthread_cancel in case of glibc calls _Unwind_ForcedUnwind from a signal on13// the child_thread. This test ensures sigreturn is handled correctly (see:14// UnwindCursor<A, R>::setInfoForSigReturn).15 16#include <cstdlib> // defines __BIONIC__17 18// Android/Bionic does not support pthread_cancel.19#ifdef __BIONIC__20int main(int, char**) { return 0; }21#else22 23#include <chrono>24#include <condition_variable>25#include <pthread.h>26#include <unistd.h>27 28using namespace std::chrono_literals;29 30std::condition_variable cv;31std::mutex cv_m;32bool thread_ready = false;33 34static void* test(void* arg) {35  (void)arg;36  thread_ready = true;37  cv.notify_all();38 39  // This must be a pthread cancellation point.40  while (1)41    sleep(100);42 43  return (void*)1;44}45 46int main(int, char**) {47  pthread_t child_thread;48  std::unique_lock<std::mutex> lk(cv_m);49  pthread_create(&child_thread, 0, test, (void*)0);50 51  if (!cv.wait_for(lk, 100ms, [] { return thread_ready; }))52    return -1;53 54  pthread_cancel(child_thread);55  pthread_join(child_thread, NULL);56  return 0;57}58#endif59