The POSIX thread functions return 0 on success and return an error number on failure. Although this is stated correctly in the text, most of the examples incorrectly assume that errno is set. Below are the changes that need to be made to correct these errors.
else if (error=pthread_create(&tid, NULL, process_fd, (void *)&fd)) fprintf(stderr,"Could not create thread: %s\n",strerror(error));
page 347, Program 9.7, include the declaration: int error; in monitor_fd and replace the second for loop with:
for (i = 0; i < num_fds; i++) if (error=pthread_create((tid + i), NULL, process_fd, (void *)(fd + i))) fprintf(stderr, "Could not create thread %d: %s\n", i, strerror(error));
page 349, Example 9.5, include the declaration: int error; and replace the last two lines with:
else if (error=pthread_create(& copy_tid, NULL, copy_file, (void *)myarg)) fprintf(stderr,"Thread creation was not successful: %s\n", strerror(error));
page 352, Program 9.9, insert the declaration int error after the first line on this page and replace the four lines at the end of the first for loop with:
if (error=pthread_create(&copiertid[i], NULL, copy_file, (void *)fd[i])) fprintf(stderr, "Could not create thread %d: %s\n", i,strerror(error));
pages 354, 355, Program 9.10, in main, insert the declaration int error, replace the last 4 lines of the first for loop with:
if (error=pthread_create(&copiertid[i], NULL, copy_file, (void *)fd)) fprintf(stderr, "Could not create thread %d: %s\n", i, strerror(error));and replace the first three lines in the second for loop with:
if (error=pthread_join(copiertid[i], (void **)&(bytes_copied_p))) fprintf(stderr, "No thread %d to join: %s\n", i, strerror(error));
page 362, Example 9.6, replace everything after the declaration of fd with:
int error; if (error=pthread_attr_init(&my_tattr)) fprintf(stderr,"Could not initialize thread attribute: %s/n", strerror(error)); else if (error=pthread_attr_getschedparam(&my_tattr, ¶m)) fprintf(stderr,"Could not get scheduling parameters: %s\n", strerror(error)); else { param.sched_priority = HIGHPRIORITY; if (error=pthread_attr_setschedparam(&my_tattr, ¶m)) fprintf(stderr,"Could not set priority: %s\n",strerror(error)); else if (error=pthread_create(&my_tid, &my_tattr, do_it, (void *)&fd)) fprintf(stderr,"Could not create copier thread: %s\n", strerror(error)); }
if (pthread_mutex_init(&my_lock, NULL)) fprintf(stderr,"Could not initialize my_lock");
page 370, Program 10.2, change the last 4 lines on the page to
if (pthread_create(&constid, NULL, consumer, NULL)) fprintf(stderr,"Could not create consumer"); else if (pthread_create(&prodtid, NULL, producer, NULL)) fprintf(stderr,"Could not create producer");