While hunting for why the jdk's stack overflow execptions were randomly
not working, I determined the root cause was that pthread_main_np(3) 
randomly fails to work properly. Reproduced on sparc64, amd64, and
aarch64. On i386 the standalone test program doesn't reproduce the
problem. However, I observed it happens there too with the jdk.

to reproduce:

cc -g main_np.c -o main_np -pthread
while ./main_np; do echo ok;done
...
main_np: pthread_main_np failed: Undefined error: 0

============ main_np.c ==================
#include <err.h>
#include <pthread.h>
#include <pthread_np.h>

#define NTHREADS 40

pthread_t threads[NTHREADS];
 
void *
thread_start(pthread_t *thread) {
    if (pthread_main_np() != 0)
        err(1, "pthread_main_np failed");
    return(NULL);
}

int
main(int argc, char *argv[])
{
    long t_num;

    /* startup threads */
    for (t_num=0; t_num < NTHREADS; t_num++) {
        int ret = pthread_create(&threads[t_num], NULL,
          (void* (*)(void*))thread_start, &threads[t_num]);
        if (ret != 0)
            err(1, "pthread_create failed");
    }

    /* wait for threads to finish */
    for (t_num=0; t_num < NTHREADS; t_num++) {
        if (pthread_join(threads[t_num], NULL) != 0)
            err(1, "pthread_join failed");
    }

    return 0;
}

Reply via email to