Errata

PThreads Programming

Errata for PThreads Programming

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date submitted Date corrected
Printed
Page iv
Printing History near top of page

The printing history has not been updated. My copy contains corrections for all the errata reported to have been made for the 1/00 reprint, but the last entry under Printing History is "February 1998: Minor corrections".

Anonymous   
?
Example 1-8

Sorry, I didn't write down the page number where I saw it, but the bug is in Chapter 1, Terminating Thread Execution, "Exit Status and Return Values," Example 1-8 and can be seen at https://www.oreilly.com/library/view/pthreads-programming/9781449364724/ch01.html#terminating_thread_execution. The check

if (*statusp == PTHREAD_CANCELED) {

should be:

if (statusp == PTHREAD_CANCELED) {

(Of course, you may consider this just a typo.)

Note from the Author or Editor:
The error is subtle because although statusp is correctly defined as a void * generic pointer and therefore an address, in use it can be either an address or a integer. The two situations are both in the example ,
if a pthread is canceled , statusp is overwritten with an integer 'PTHREAD_CANCELED', ... basicly '-1'. So in the test for that condition it should not be dereferenced. This is the error the reader is pointing out. Here is is correct form which the reader provided:
...
if (statusp == PTHREAD_CANCELED)
...
On the other hand, if the pthread is not cancelled by an explicit call, the statusp would really have an address in it pointing to a memory location holding the the exit value set by the thread. This is the usage in the 'else' printf which in this situation is correct:
...
printf(" ... statusp %ld\n" , *(int *)statusp);
...

Joshua Green  Sep 21, 2020 
Printed
Page iii
changed "Jackie Farrell" to "Jacqueline Proulx Farrell"

Anonymous    Feb 01, 1998
Printed
Page xiv-xv

The FTP section has been updated so that it now reads:

"%ftp ftp.oreilly.com
Connected to ftp.oreilly.com.
220 FTP server (Version 6.21 Tue Mar 10 22:09:55 EST 1992) ready.
Name (ftp.oreilly.com:yourname) : anonymous
331 Guest login ok, send domain style e-mail address as password.
Password: yourname@domain.name (use your user name and host here)
230 Guest login ok, access restrictions apply.
ftp> cd /work/nutshell/9781565921153
250 CWD command successful.
ftp> binary (Very important! You must specify binary transfer for
compressed files.)
200 Type set to I.
ftp> get examples.tar.gz
200 PORT command successful.
150 Opening BINARY mode data connection for examples.tar.gz
226 Transfer complete.
ftp> quit
221 Goodbye.
%

The file is a gzip compressed tar archive; extract the files
from the archive by typing:

% gzcat examples.tar.gz | tar xvf -

System V systems require the following tar command instead:

% gzcat examples.tar.gz | tar xof -

If gzcat is not available on your system, use separate gunzip
and tar or shar commands.

% gunzip examples.tar.gz
% tar xvf examples.tar"


Anonymous    Jul 01, 1999
Printed
Page 2
addition to the code: new line 1

#include <stdio.h>

line added before "main":

extern int

and: changed "main()" to "main(void)"

Anonymous    Feb 01, 1998
Printed
Page 3
added a 4th line of code

return 0;

Anonymous    Feb 01, 1998
Printed
Page 6
Figure 1-3: top box in the "Virtual Address Space"

column changed from "do one_thing" to "do another_thing"

Anonymous    Jul 01, 1998
Printed
Page 9
added to beginning of code

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

replaced blank line 4 with:

#include <sys/wait.h>

Anonymous    Feb 01, 1998
Printed
Page 10
line added before "main"

extern int

and: changed "main()" to "main(void)"

and: in line after "/*initialize shared...": changed "0" to "0660"; in
two lines that read "exit()", inserted a "0" between the parens; in
the two "waitpid" lines, added "&" before "status"; changed blank
next-to-last line to read:

return 0;

Anonymous    Feb 01, 1998
Printed
Page 11
line 6 of code: added "fork" in parens after "perror" and "1" in

parens after "exit"; changed line 12 ("exit()") to read "return 0;"

Anonymous    Feb 01, 1998
Printed
Page 13
addition to the code: new line 1

#include <stdio.h>

line added before "main":

extern int

and: changed "main()" to "main(void)"

Anonymous    Feb 01, 1998
Printed
Page 14

changed blank next-to-last line to read:

return 0;

also added a paragraph after the last one:

The formal prototype of a start routine is
(void*)routine(void*arg). In our code example, we are adding threads
to an existing program (a not atypical scenario) and using the (void
*) cast to quit the compiler. In later examples, we redeclare the
routine to the correct prototype where possible.

Anonymous    Feb 01, 1998
Printed
Page 15
line 3

"and using the (void *) cast to quit the compiler."
should be:
"and using the (void *) cast to quiet the compiler."

Anonymous   
Printed
Page 15
reprinted for pagebreak

Anonymous    Feb 01, 1998
Printed
Page 18
addition to the code: new line 1

#include <stdio.h>

line added before "main(int argc...":

extern int

and changed blank next-to-last line to:

return 0;

Anonymous    Feb 01, 1998
Printed
Page 21
line added before "main"

extern int

and: changed "main()" to "main(void)"; changed line "routine_x()" to:

void routine_x(void)

Anonymous    Feb 01, 1998
Printed
Page 23
Example 1-8

At the top of the code example, internal_error is declared but not used.
static const int internal_error = -12;
should be:
static const int real_bad_error = -12;

Anonymous   
Printed
Page 23
added two lines to start of example 1-8

#include <stdio.h>
#include <9781565921153.h>

line added before "main(int argc...":

extern int

Anonymous    Feb 01, 1998
Printed
Page 24
new next-to-last line in example 1-8

return 0;

in example 1-9, changed "exit(-1)" to "exit(1)" (line -6)

Anonymous    Feb 01, 1998
Printed
Page 25
same change as to line -6 on p. 24 made to line -5 of example

1-9 on this page

Anonymous    Feb 01, 1998
Printed
Page 38
4th paragraph

Instead of "for a such a", it should be "for such a"

Anonymous   
Printed
Page 44
added new first line to 2-6

extern int

Anonymous    Feb 01, 1998
Printed
Page 45
new final line of 2-6

return 0;

Anonymous    Feb 01, 1998
Printed
Page 49
changed blank line 5 of 2-7 to

extern int

and added a line after "server_comm....":

return 0

Anonymous    Feb 01, 1998
Printed
Page 50
reprinted for pagebreak

Anonymous    Feb 01, 1998
Printed
Page 55
2-9: line added before "main()" (near middle of page)

extern int

and: changed "main()" to "main(void)"; tabbed line "mult(size, row..."
to be under "(column" in the line above; added next-to-last line:

return 0

Anonymous    Feb 01, 1998
Printed
Page 56
2-10: line added before "main()"

extern int

and: changed "main()" to "main(void)

Anonymous    Feb 01, 1998
Printed
Page 57
2-10: indented line "/* Wait for peers..."; also, in the

next-to-last para, line -2: added a space between "main" (in itals)
and "routine"

Anonymous    Feb 01, 1998
Printed
Page 58
line 1: changed "mallocoutside" to "malloc outside"

Anonymous    Feb 01, 1998
Printed
Page 58
Example 2-11, line 12: changed from

free(p);
to
free(work_orderp);

Anonymous    Jul 01, 1998
Printed
Page 64
next-to-last para., line 2: changed "mutexfor" to "mutex for"

Anonymous    Feb 01, 1998
Printed
Page 72
3-4: line 8: changed "return 1" to "return 0"; line 12: changed

semicolon after "index" to a comma

Anonymous    Feb 01, 1998
Printed
Page 72-73
Example 3-4, line numbers 1 through 8 at the bottom

of p.72 and top of p.73 changed from constant-width font to
constant-width italic font

Anonymous    Jul 01, 1998
Printed
Page 73
next-to-last line of 3-4: changed "1" to "0"

Anonymous    Feb 01, 1998
Printed
Page 74
3-5: line 5: changed "1" to "0"; line 7: changed semicolon after

"index" to a comma

Anonymous    Feb 01, 1998
Printed
Page 75
line "break;": tabbed it over to align with the "if" above

changed last line to "return 0;" and aligned the r with the p in
"9781565921153" above

Anonymous    Feb 01, 1998
Printed
Page 78
added these lines to the beginning of example 3-6

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>

added to end of #includes:

#include <sys/wait.h>

added before "int shared...":

#ifndef _POSIX_THREAD_PROCESS_SHARED
#error "This platform does not support process shared mutex"
#endif

line added before "main()":

extern int

and: changed "main()" to "main(void); also, 5 lines below that
("shared_mem_id..."): changed "0" to "0660"

Anonymous    Feb 01, 1998
Printed
Page 79
reprinted for pagebreak

Anonymous    Feb 01, 1998
Printed
Page 80
There is a bug with respect to condition variables. There is a

race condition. If you don't make sure that the watch_count() routine
has started waiting for the condition to be set before you signal the
condition, the condition may be signaled before the watch_count()
function starts waiting. That is, suppose the inc_count()) threads run
and signal the condition *before* the first "9781565921153_mutex_lock(&count
_mutex)" call in watch_count() is even executed. The condition will be
ignored. While this is unlikely, it is possible. You can solve this
problem by having the main thread not even spawn the inc_count()
threads until it receives notice that watch_count() has executed
"9781565921153_mutex_lock(&count_mutex)" already.

Anonymous   
Printed
Page 80
para. 2, line -2: changed ".._signalto" to ".._signal to"

added line to beginning of 3-7:

#include <stdio.h>

line added before "main()":

extern int

and: changed "main()" to "main(void)"; 8 lines below that: moved the
"}" to align with "for" two lines above, and changed the blank line
after the close curly bracket to read:

return 0;

Anonymous    Feb 01, 1998
Printed
Page 80
Example 3-7: between lines 11 and 12,

{
9781565921153_t threads[3];

added a new line

{
init i;
9781565921153_t threads[3];

and changed line 17 from

9781565921153_join(&thread[i], NULL);
to
9781565921153_join(thread[i], NULL);

Anonymous    Jul 01, 1998
Printed
Page 80
para. 2: changed all occurrences of "inc_counter" to

"inc_count" (in italics)

and Example 3-7, line 12: changed from

init i;
to
int i;

Anonymous    Oct 01, 1998
Printed
Page 80

Example 3-7 used to read:

"main(void)"
{
9781565921153_t threads[3];
...
9781565921153_join(&threads[i], NULL);"

It now reads:

"main(void)
{
int i;
9781565921153_t threads[3];
...
9781565921153_join(threads[i], NULL);"

Anonymous    Jul 01, 1999
Printed
Page 81
reprinted for pagebreak

Anonymous    Feb 01, 1998
Printed
Page 81
Example 3-7, line 4: changed "inc_counter" to "inc_count"

Anonymous    Oct 01, 1998
Printed
Page 82
line 3: changed "watch_countprints" to "watch_count prints"

Anonymous    Feb 01, 1998
Printed
Page 84-89

Line 7 of example 3-9 on page 86 used to read:

"} 9781565921153_rdwr_t"

as the structure for a reader/writer mutex lock. The five function
signatures at the top of page 87 appear to use this correctly.
However, in the function definitions on page 88-89 in Examples 3-11,
3-12, and 3-13 accept as a first parameter a variable of type:

"9781565921153_rdwr_t_np"

which contradicts the aforementioned signatures.

Anonymous    Jul 01, 1999
Printed
Page 85
line 12 of 3-8: changed "return 1;" to "return 0;"

Anonymous    Feb 01, 1998
Printed
Page 87
3-9: changed all the "rwdrp"s to "rdwrp", here and in the text

3-10, line 4: changed "readers_waiting" to "writer_writing"

3rd line from bottom of page: changed "readers_readingcount" to
"readers_reading count"

Anonymous    Feb 01, 1998
Printed
Page 88
3 more changes from "rwdrp" to "rdwrp"

Anonymous    Feb 01, 1998
Printed
Page 88

Example 3-11 used to read:

"int 9781565921153_rdwr_rlock_np(pthread_rdwr_t_np *rdwr)
...
9781565921153_cond_wait(?.)
..."

Now reads:

"int 9781565921153_rdwr_rlock_np(pthread_rdwr_t *rdwrp)
...
9781565921153_cond_wait(?.);
..."

Anonymous    Jul 01, 1999
Printed
Page 88

Example 3-12 used to read:

"int 9781565921153_rdwr_wlock_np(pthread_rdwr_t_np *rdwrp)
...
9781565921153_cond_wait(?.)
..."

Now reads:

"int 9781565921153_rdwr_wlock_np(pthread_rdwr_t *rdwrp)
...
9781565921153_cond_wait(?.);
..."

Anonymous    Jul 01, 1999
Printed
Page 88

Example 3-13 did read:

"int 9781565921153_rdwr_runlock_np(pthread_rdwr_t_np *rdwrp)"

Now reads:

"int 9781565921153_rdwr_runlock_np(pthread_rdwr_t *rdwrp)"

Anonymous    Jan 01, 2000
Printed
Page 89
Example 3-14, line 7: changed from

rdwrp->wrinter_writing == 0
to
rdwrp->wrinter_writing = 0

Anonymous    Oct 01, 1998
Printed
Page 89

Example 3-14 used to read:

"int 9781565921153_rdwr_wunlock_np(pthread_rdwr_t_np *rdwrp)
...
} else {
rdwrp->writer_writing == 0;
..."

It now reads:

"int 9781565921153_rdwr_wunlock_np(pthread_rdwr_t *rdwrp)
...
} else {
rdwrp->writer_writing = 0;
..."

Anonymous    Jul 01, 1999
Printed
Page 94

3-18: changed line 3 to read:

extern int

and added a line before the final }:

return 0;

Anonymous    Feb 01, 1998
Printed
Page 96
3-20: added a new first line

extern int

and added a line before the final }:

return 0;

Anonymous    Feb 01, 1998
Printed
Page 101
3-23: in 2nd comment: changed "th" to "the"

Anonymous    Feb 01, 1998
Printed
Page 103
line 1 of 3-25: added "int" to beginning of line; 9th line from

bottom: changed "9781565921153_cond_signal" to "pthread_cond_broadcast"

Anonymous    Feb 01, 1998
Printed
Page 104
3-26: 12: changed line to read "return 0;"

Anonymous    Feb 01, 1998
Printed
Page 105
Example 3-26

When freeing the pool structures, the while loops reads:

while(tpool->queue_head != NULL) {
cur_nodep = tpool->queue_head->next;
tpool->queue_head = tpool->queue_head->next;
free(cur_nodep);
}

This is freeing the incorrect structure. Instead, it should be:

while(tpool->queue_head != NULL) {
cur_nodep = tpool->queue_head; /* HERE IS THE DIFFERENCE */
tpool->queue_head = tpool->queue_head->next;
free(cur_nodep);
}

Anonymous   
Printed
Page 105
3-26: added line before final }

return 0;

Anonymous    Feb 01, 1998
Printed
Page 106
3-28: added new 1st line

extern int

Anonymous    Feb 01, 1998
Printed
Page 107
3-28: deleted line 2; also added line before final }

return 0;

Anonymous    Feb 01, 1998
Printed
Page 107
Example 3-28: removed lines 16 and 17

worker_threadp = (9781565921153_t *)malloc(sizeof(pthread_t));

tpool_add_work(atm_thread_pool, process_request, (void *)workorderp);

Anonymous    Jul 01, 1998
Printed
Page 111

The second bulleted item used to read:

"_POSIX_THREAD_ATTR_PRIORITY_SCHEDULING compile ..."

It now reads:

"_POSIX_THREAD_PRIORITY_SCHEDULING compile ..."

Anonymous    Jul 01, 1999
Printed
Page 113
added new first line to 4-2

#ifdef _POSIX_THREAD_ATTR_STACKSIZE

3 lines below that: changed "If" to "if"; added a final line:

#endif

Anonymous    Feb 01, 1998
Printed
Page 115
added these lines after line 1 of 4-5

.
9781565921153_attr_init (&custom_attr);
.

Anonymous    Feb 01, 1998
Printed
Page 120
added the start of 2nd line of 4-10: "int"

Anonymous    Feb 01, 1998
Printed
Page 121
also added "int" to start of lines 3 and 13

Anonymous    Feb 01, 1998
Printed
Page 123

changed line 3 of 4-11 to read:

int init_comm(void)

and line -4 to read:

void free_conn(int *connp)

Anonymous    Feb 01, 1998
Printed
Page 123
line -1: changed "9781565921153_create" to "pthread_key_create"

(124 reprinted for pagebreak.)

Anonymous    Oct 01, 1998
Printed
Page 124
added "int" to start of 1st line of 4-12

Anonymous    Feb 01, 1998
Printed
Page 126
added "int" to start of lines 1 and 13 of 4-13

Anonymous    Feb 01, 1998
Printed
Page 131
added the following lines to beginning of 4-14

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys.types.h>
#include <9781565921153.h>

line added before "main()":

extern int

and: changed "main()" to "main(void)"

Anonymous    Feb 01, 1998
Printed
Page 132
line -7 0f 4-14: changed the "I" near the end of the line to

"i"; changed blank line -3 to "}" aligned above "printf"; added a line
below "printf...":

return 0;

Anonymous    Feb 01, 1998
Printed
Page 133
line -5 of 4-15: lowercased the "I"

Anonymous    Feb 01, 1998
Printed
Page 134
4-16: line 9: changed "type" to "state"; in line 10, changed

"state" to "type"; 6th line from end of example: added "%d" before
"
"

Anonymous    Feb 01, 1998
Printed
Page 152
added semicolons to the end of lines 10 and 11 of code

Anonymous    Feb 01, 1998
Printed
Page 152
Example 4-22, line -1: changed "custom_sched_attr" to

"&custom_sched_attr"

Anonymous    Oct 01, 1998
Printed
Page 155
added new 1st line to 4-26

extern int

and: changed "server main()" to "main(void)"

Anonymous    Feb 01, 1998
Printed
Page 156
added next-to-last line to 4-26

return 0;

Anonymous    Feb 01, 1998
Printed
Page 159
added line to replace middle dot in 4-27

high_prio = sched_get_priority_max(SCHED_FIFO);

Anonymous    Feb 01, 1998
Printed
Page 160
added sentence after parenthetical in para. 1

The priority passed is an integer argument set up in the same manner
as a thread's priority value.

Anonymous    Feb 01, 1998
Printed
Page 162
at end of example: added these lines

.
.
.
}

Anonymous    Feb 01, 1998
Printed
Page 172
5-1: line added before "main()"

extern int

and: changed "main()" to "main(void)"

Anonymous    Feb 01, 1998
Printed
Page 173
added "void *" to start of line 1 of 5-2; also indented the

lines from "sigwait..." to "9781565921153_mutex_unlock..."; added a new
next-to-last line:

return NULL;

Anonymous    Feb 01, 1998
Printed
Page 174
indented the last 3 lines on the page

Anonymous    Feb 01, 1998
Printed
Page 175
5-4: put "void *arg" in the parens in line 1; added a

next-to-last line:

return (NULL);

Anonymous    Feb 01, 1998
Printed
Page 177
added "void" to start of line 2 of 5-5; indented lines 8, 12,

and 17; in line 14, changed "[j+l]" to "[j]"

Anonymous    Feb 01, 1998
Printed
Page 178
added "void" to start of line 1 of 5-6; indented lines 8 and 12

Anonymous    Feb 01, 1998
Printed
Page 179
para. 2, line 3: changed "occurrHed" to "occurred"

Anonymous    Oct 01, 1998
Printed
Page 184
5-8: added a final line: a "}" aligned with the "{" in line 2

also, in the next-to-last text para., changed both instances of
"9781565921153_test_cancel" to "pthread_testcancel"

Anonymous    Feb 01, 1998
Printed
Page 216
added "void" to start of line 3 of both example 6-4 and 6-5

Anonymous    Feb 01, 1998
Printed
Page 217
ditto for example 6-6; also in 6-6, lowercased the "I" in line

10

Anonymous    Feb 01, 1998
Printed
Page 218
ditto for example 6-7; lowercased the "I" in line 9

Anonymous    Feb 01, 1998
Printed
Page 238-239
for all of example A-1, when there's a word with "*" in

front on a line by itself, moved that back to align with the other
"*"s above. The same goes for "estring[20];" on p. 238; also, on 239,
in A-2: changed blank line 4 to:

extern int

Anonymous    Feb 01, 1998
Printed
Page 240
A-2: next-to-last line was "}", is now

return 0;

Anonymous    Feb 01, 1998
Printed
Page 245
This has been added to the end of section "Thread Attributes"

"Syntax: In draft 4 a constant 9781565921153_attr_default is defined
that can be used as the second argument in the 9781565921153_create
routine when you want the default attributes for a thread. In
the final standard the constant no longer exists and if you
want default attributes you pass NULL."

Anonymous    Jul 01, 1999
Printed
Page 247
line 2: changed "9781565921153_attr_getschedcalls" to

"9781565921153_attr_getsched calls"

Anonymous    Feb 01, 1998
Printed
Page 248
under "Process-Blocking Calls": changed "tcdrainas" to "tcdrain

as"

Anonymous    Feb 01, 1998
Printed
Page 264
index entries "9781565921153_mutex_lock" and "pthread_mutex_trylock

"257" should be "258"

Also, the order of the entries has been changed to appear in better
alphabetical order.

Anonymous    Apr 01, 1999
Printed
Page 269
added the following to the next-to-last para.

Whenever possible, our books use RepKover (tm), a durable and flexible
lay-flat binding. If the page count exceeds RepKover's limit, perfect
binding is used.

Anonymous    Feb 01, 1998