Denys Vlasenko | 68ba190 | 2015-03-21 20:59:39 +0100 | [diff] [blame] | 1 | // This testcase, when run with large number of threads |
| 2 | // under stace -f, may never finish because strace does not |
| 3 | // ensure any fairness in thread scheduling: |
| 4 | // it restarts threads as they stop. If daughter threads crowd out |
| 5 | // the "mother" and _they_ get continually restarted by strace, |
| 6 | // the end of spawning loop will never be reached. |
| 7 | // |
| 8 | // Also, it is a testcase which triggers the |
| 9 | // "strace: Exit of unknown pid 32457 seen" |
| 10 | // message when on testcase exit, strace sees deaths of newly-attached |
| 11 | // threads _before_ their first syscall stop. |
| 12 | // |
| 13 | #include <stdio.h> |
| 14 | #include <pthread.h> |
| 15 | #include <unistd.h> |
| 16 | #include <sys/types.h> |
| 17 | #include <signal.h> |
| 18 | #include <stdlib.h> |
| 19 | |
| 20 | static int thd_no; |
| 21 | |
| 22 | static void *sub_thd(void *c) |
| 23 | { |
| 24 | dprintf(1, "sub-thread %d created\n", ++thd_no); |
| 25 | for (;;) |
| 26 | getuid(); |
| 27 | return NULL; |
| 28 | } |
| 29 | |
| 30 | int main(int argc, char *argv[]) |
| 31 | { |
| 32 | int i; |
| 33 | pthread_t *thd; |
| 34 | int num_threads = 1; |
| 35 | |
| 36 | if (argv[1]) |
| 37 | num_threads = atoi(argv[1]); |
| 38 | |
| 39 | thd = malloc(num_threads * sizeof(thd[0])); |
| 40 | dprintf(1, "test start, num_threads:%d...\n", num_threads); |
| 41 | |
| 42 | for (i = 0; i < num_threads; i++) { |
| 43 | pthread_create(&thd[i], NULL, sub_thd, NULL); |
| 44 | dprintf(1, "after pthread_create\n"); |
| 45 | } |
| 46 | |
| 47 | /* Exit. This kills all threads */ |
| 48 | return 0; |
| 49 | } |