Break the limit of threading, segmentation fault
- by user353573
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);
}
}