product.asp
来自「Pthread lib库完整说明文档」· ASP 代码 · 共 548 行 · 第 1/5 页
ASP
548 行
<blockquote><pre><tt>
[14] status = pthread_mutex_lock (&crew->mutex);
[15] if (status != 0)
[16] err_abort (status, "Lock crew mutex");
[17]
[18] /*
[19] * There won't be any work when the crew is created, so wait
[20] * until something's put on the queue.
[21] */
[22] while (crew->work_count == 0) {
[23] status = pthread_cond_wait (&crew->go, &crew->mutex);
[24] if (status != 0)
[25] err_abort (status, "Wait for go");
[26] }
[27]
[28] status = pthread_mutex_unlock (&crew->mutex);
[29] if (status != 0)
[30] err_abort (status, "Unlock mutex");
[31]
[32] DPRINTF (("Crew %d starting\n", mine->index));
[33]
[34] /*
[35] * "struct dirent" is funny, because POSIX doesn't require
[36] * the definition to be more than a header for a variable
[37] * buffer. Thus, allocate a "big chunk" of memory, and use
[38] * it as a buffer.
[39] */
[40] entry = (struct dirent*)malloc (
[41] sizeof (struct dirent) + crew->name_max);
[42] if (entry == NULL)
[43] errno_abort ("Allocating dirent");
[44]
</tt></pre></blockquote>
<hr>
<p>Page 112. Correct line 136 of the example code to use the new
<tt>path_max</tt> field of <tt>crew_t</tt>:
<blockquote><pre><tt>
[136] new_work->path = (char*)malloc (crew->path_max);
</tt></pre></blockquote>
<hr>
<p>Page 117. Correct line 29 of the example code to use the new
<tt>path_max</tt> field of <tt>crew_t</tt>:
<blockquote><pre><tt>
[29] crew->path_max = pathconf (filepath, _PC_PATH_MAX);
</tt></pre></blockquote>
<hr>
<p>Page 118. Correct 9 lines (30, 32, 37, 38, 40, 46, 47, 48, and 53)
of the example code to use the new <tt>path_max</tt> and
<tt>name_max</tt> fields of <tt>crew_t</tt>. For reference, all of
lines 30 through 53 are shown here:
<blockquote><pre><tt>
[30] if (crew->path_max == -1) {
[31] if (errno == 0)
[32] crew->path_max = 1024; /* "No limit" */
[33] else
[34] errno_abort ("Unable to get PATH_MAX");
[35] }
[36] errno = 0;
[37] crew->name_max = pathconf (filepath, _PC_NAME_MAX);
[38] if (crew->name_max == -1) {
[39] if (errno == 0)
[40] crew->name_max = 256; /* "No limit" */
[41] else
[42] errno_abort ("Unable to get NAME_MAX");
[43] }
[44] DPRINTF ((
[45] "PATH_MAX for %s is %ld, NAME_MAX is %ld\n",
[46] filepath, crew->path_max, crew->name_max));
[47] crew->path_max++; /* Add null byte */
[48] crew->name_max++; /* Add null byte */
[49] request = (work_p)malloc (sizeof (work_t));
[50] if (request == NULL)
[51] errno_abort ("Unable to allocate request");
[52] DPRINTF (("Requesting %s\n", filepath));
[53] request->path = (char*)malloc (crew->path_max);
</tt></pre></blockquote>
<hr>
<p>Page 207. In the <tt>flock.c</tt> example, each of the 3 inputs are echoed
with the label "Thread 1". This makes no sense. I actually fixed these problems
just about 4 years ago, along with some type casting problems, but I overlooked
the label changes when writing the errata. The labels in lines 69 and 74 should
be changed to "Thread 2" and "Thread 3", respectively. For reference, those
2 changed lines are shown with the intervening lines (unchanged) for context:
<blockquote>
<pre><tt>
[69] printf ("Thread 2: \"%s\"\n", (char*)string);
[70] free (string);
[71] status = pthread_join (thread3, &string);
[72] if (status != 0)
[73] err_abort (status, "Join thread");
[74] printf ("Thread 3: \"%s\"\n", (char*)string);
</tt></pre>
</blockquote>
<hr>
<p>Page 241. I'm not quite sure how this could have happened, but it has been
pointed out (and I think I've quite carefully verified) that the Mock Turtle
quote used here actually comes from <i>Alice's Adventures in Wonderland</i>
rather than <i>Through the Looking-Glass</i>. The attribution line should
be changed accordingly. In addition, it would be technically correct to remove
page 241 from the list of quotes attributed to <i>Through the Looking-Glass</i>
on "page vi" immediately preceding the Contents page, and add page 241 to
the list of quotes attributed to <i>Alice's Adventures in Wonderland.</i>.
<br>
<br>
<hr>
<p>On page 244, at the second line in the 5th paragraph, in the sentence beginning
"The <tt>threshhold</tt> member is the number of threads in the group [...]",
the actual name (and correct spelling) of the structure member is <tt>threshold</tt>.
Replace <tt>threshhold</tt> by <tt>threshold</tt>.
<br>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?