Debugging threads with HP Wilde Beest
l1 = &job_lock1
l2 = &job_lock2
}
else {
l1 = l2 = &job_lock1
}
alarm(20);
/* Create two threads to do the work */
ret_val = pthread_create(&tid1, (pthread_attr_t *)NULL,
(void *(*)())consumer_thread, (void *) l1);
check_error(ret_val, "pthread_create 1 failed");
ret_val = pthread_create(&tid2, (pthread_attr_t *)NULL,
(void *(*)())producer_thread, (void *) l1);
check_error(ret_val, "pthread_create 2 failed");
if (l1 != l2) {
ret_val = pthread_create(&tid3, (pthread_attr_t *)NULL,
(void *(*)())consumer_thread, (void *) l2);
check_error(ret_val, "pthread_create 1 failed");
ret_val = pthread_create(&tid4, (pthread_attr_t *)NULL,
(void *(*)())producer_thread, (void *) l2);
check_error(ret_val, "pthread_create 2 failed");
}
/* Wait for the threads to finish */
ret_val = pthread_join(tid1, (void **)NULL);
check_error(ret_val, "pthread_join: tid1");
ret_val = pthread_join(tid2, (void **)NULL);
check_error(ret_val, "pthread_join: tid2");
if (l1 != l2) {
ret_val = pthread_join(tid3, (void **)NULL);
check_error(ret_val, "pthread_join: tid3");
ret_val = pthread_join(tid4, (void **)NULL);
check_error(ret_val, "pthread_join: tid4");
}
exit(0);
}
void
fatal_error(int err_num, char *function)
{
char *err_string;
err_string = strerror(err_num);
fprintf(stderr, "%s error: %s\n", function, err_string);
exit(-1);
28