main_thread_exception.c 644 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include <stdio.h>
  6. #include <pthread.h>
  7. typedef struct ThreadArgs {
  8. int start;
  9. int length;
  10. } ThreadArgs;
  11. void *
  12. thread(void *args)
  13. {
  14. while (1) {
  15. /* When other threads (including main thread) throw exception,
  16. this thread can successfully exit the dead loop */
  17. }
  18. }
  19. int
  20. main()
  21. {
  22. pthread_t tids;
  23. if (pthread_create(&tids, NULL, thread, NULL) != 0) {
  24. printf("pthread_create failed\n");
  25. }
  26. /* Trigger an exception */
  27. __builtin_trap();
  28. return 0;
  29. }