brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 5de2001 Raw
39 lines · cpp
1// RUN: %check_clang_tidy %s bugprone-bad-signal-to-kill-thread %t2 3#define SIGTERM 154#define SIGINT 25using pthread_t = int;6using pthread_attr_t = int;7 8int pthread_create(pthread_t *thread, const pthread_attr_t *attr,9                   void *(*start_routine)(void *), void *arg);10 11int pthread_kill(pthread_t thread, int sig);12 13int pthread_cancel(pthread_t thread);14 15void *test_func_return_a_pointer(void *foo);16 17int main() {18  int result;19  pthread_t thread;20 21  if ((result = pthread_create(&thread, nullptr, test_func_return_a_pointer, 0)) != 0) {22  }23  if ((result = pthread_kill(thread, SIGTERM)) != 0) {24    // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: thread should not be terminated by raising the 'SIGTERM' signal [bugprone-bad-signal-to-kill-thread]25  }26 27  //compliant solution28  if ((result = pthread_cancel(thread)) != 0) {29  }30 31  if ((result = pthread_kill(thread, SIGINT)) != 0) {32  }33  if ((result = pthread_kill(thread, 0xF)) != 0) {34    // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: thread should not be terminated by raising the 'SIGTERM' signal [bugprone-bad-signal-to-kill-thread]35  }36 37  return 0;38}39