Break the limit of threading, segmentation fault

Posted by user353573 on Stack Overflow See other posts from Stack Overflow or by user353573
Published on 2010-05-29T14:28:12Z Indexed on 2010/05/29 14:32 UTC
Read the original article Hit count: 125

Filed under:

use pthread_create to create limited number of threads running concurrently Successfully compile and run

However, after adding function pointer array to run the function, Segmentation fault

Where is wrong?

workserver number: 0 Segmentation fault

void* workserver(void arg) { int status; while(true) { printf("workserver number: %d\n", (int)arg); ( job_queue[(int)arg])(); sleep(3);

    status = pthread_mutex_lock(&data.mutex);
    if(status != 0)
        printf("%d lock mutex", status);
    data.value = 1;
    status = pthread_cond_signal(&data.cond);
    if(status != 0)
        printf("%d signal condition", status);
    status = pthread_mutex_unlock(&data.mutex);
    if(status != 0)
        printf("%d unlock mutex", status);
}

}

© Stack Overflow or respective owner

Related posts about c