runtimeverification / rv-predict

Code for improved rv-predict and installer
BSD 3-Clause "New" or "Revised" License
2 stars 3 forks source link

thread-specific data workaround in #1000 isn't safe with pthread_cancel #1038

Closed maya-rv closed 5 years ago

maya-rv commented 5 years ago

cFE/OSAL bin-sem-flush-test segfaults. This might be a minimal test case of it.

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static pthread_key_t msg_key;

#define NUMTHREADS 4

void *thread_func(void *param)
{
    pthread_setspecific(msg_key, param);
    return NULL;
}

int main(int argc, const char *argv[])
{      
    pthread_t thread[NUMTHREADS];
    int i;

    pthread_key_create(&msg_key, NULL);

    for (i=0; i <NUMTHREADS; ++i) {
        char * m = malloc(sizeof(char)); 
        pthread_create(&thread[i], NULL, thread_func, m);
    }
    pthread_cancel(thread[0]);

    return 0;
}