Home | History | Annotate | Download | only in solaris
      1 /*
      2  * Creates 8 threads. The fifth one (counting the main thread as well)
      3  * causes a core dump.
      4  */
      5 
      6 #include <errno.h>
      7 #include <pthread.h>
      8 #include <stdio.h>
      9 #include <stdlib.h>
     10 #include <string.h>
     11 #include <unistd.h>
     12 
     13 #define NEVERENDING_SLEEP 10000
     14 
     15 static pthread_barrier_t barrier;
     16 
     17 static void *thread_func2(void *arg) {
     18    pthread_barrier_wait(&barrier);
     19    sleep(NEVERENDING_SLEEP);
     20    return NULL;
     21 }
     22 
     23 static void *thread_func3(void *arg) {
     24    pthread_barrier_wait(&barrier);
     25    sleep(NEVERENDING_SLEEP);
     26    return NULL;
     27 }
     28 
     29 static void *thread_func4(void *arg) {
     30    pthread_barrier_wait(&barrier);
     31    sleep(NEVERENDING_SLEEP);
     32    return NULL;
     33 }
     34 
     35 static void *thread_func5(void *arg) {
     36    pthread_barrier_wait(&barrier);
     37    sleep(2);
     38 
     39    char *x = (char *) 0x1;
     40    *x = 2;
     41    return NULL;
     42 }
     43 
     44 static void *thread_func6(void *arg) {
     45    pthread_barrier_wait(&barrier);
     46    sleep(NEVERENDING_SLEEP);
     47    return NULL;
     48 }
     49 
     50 static void *thread_func7(void *arg) {
     51    pthread_barrier_wait(&barrier);
     52    sleep(NEVERENDING_SLEEP);
     53    return NULL;
     54 }
     55 
     56 static void *thread_func8(void *arg) {
     57    pthread_barrier_wait(&barrier);
     58    sleep(NEVERENDING_SLEEP);
     59    return NULL;
     60 }
     61 
     62 static void *thread_func9(void *arg) {
     63    pthread_barrier_wait(&barrier);
     64    sleep(NEVERENDING_SLEEP);
     65    return NULL;
     66 }
     67 
     68 static void create_thread(void *(*thread_func)(void *))
     69 {
     70    pthread_t thread;
     71 
     72    int ret = pthread_create(&thread, NULL, thread_func, NULL);
     73    if (ret != 0) {
     74       fprintf(stderr, "pthread_create: %s (%d)\n", strerror(ret), ret);
     75       exit(1);
     76    }
     77 }
     78 
     79 int main(int argc, const char *argv[])
     80 {
     81    int ret = pthread_barrier_init(&barrier, NULL, 9);
     82    if (ret != 0) {
     83       fprintf(stderr, "pthread_barrier_init: %s (%d)\n",
     84               strerror(ret), ret);
     85       exit(1);
     86    }
     87 
     88    create_thread(thread_func2);
     89    create_thread(thread_func3);
     90    create_thread(thread_func4);
     91    create_thread(thread_func5);
     92    create_thread(thread_func6);
     93    create_thread(thread_func7);
     94    create_thread(thread_func8);
     95    create_thread(thread_func9);
     96    pthread_barrier_wait(&barrier);
     97 
     98    sleep(NEVERENDING_SLEEP);
     99    return 0;
    100 }
    101