product.asp

来自「Pthread lib库完整说明文档」· ASP 代码 · 共 548 行 · 第 1/5 页

ASP
548
字号
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Programming with POSIX庐 Threads - $43.99</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="modified_dt" content="Tue, 27 Feb 2007 05:24:17 GMT" /><meta name="Keywords" content="9780201633924 0201633922" /><script language="JavaScript" src="/display/common/javascript/global.js" type="text/JavaScript"></script><link href="/display/addison-wesley/css/addisonwesley_2005-04-29.css" rel="stylesheet" type="text/css" /></head><body onload="MM_preloadImages('/display/addison-wesley/images/topnav/mainnav/bookstore_on.gif','/display/addison-wesley/images/topnav/mainnav/home_on.gif','/display/addison-wesley/images/topnav/mainnav/safari_bookshelf_on.gif','/display/addison-wesley/images/topnav/mainnav/authors_on.gif','/display/addison-wesley/images/topnav/mainnav/promotions_on.gif','/display/addison-wesley/images/topnav/mainnav/articles_on.gif','/display/addison-wesley/images/topnav/mainnav/markets_on.gif','/display/common/images/buttons/toggle_open.gif','/display/common/images/buttons/toggle_closed.gif')"><div id="network" xmlns=""><form method="post" action=""><a href="http://www.awprofessional.com/about/network.asp"><img class="networkicon" src="/display/common/images/network/informit_network_aqua_1022.gif" alt="Informit Network" border="0" /></a><select name="selectnetwork" id="selectnetwork" onchange="jumpMenu('parent',this,0)"><option value="" selected="selected">Other Network Sites</option><option value="http://www.adobepress.com">Adobe Press</option><option value="http://www.awprofessional.com">Addison-Wesley Professional</option><option value="http://www.ciscopress.com">Cisco Press</option><option value="http://www.examcram.com">Exam Cram</option><option value="http://www.ftpress.com">FT Press</option><option value="http://www.fairshakepress.com">Fair Shake Press</option><option value="http://www.ibmpressbooks.com">IBM Press</option><option value="http://www.informit.com">Informit</option><option value="http://www.peachpit.com">Peachpit Press</option><option value="http://www.pearsoncorporatesales.com">Pearson Corporate Store</option><option value="http://www.phptr.com">Prentice Hall PTR</option><option value="http://www.quepublishing.com">Que Publishing</option><option value="http://www.samspublishing.com">Sams Publishing</option><option value="http://www.whartonsp.com">Wharton School Publishing</option></select></form></div><div id="header"><div id="containerWide"><div class="containerCenter"><a href="/index.asp"><img id="logo" src="/display/addison-wesley/images/logos/header_logo.gif" alt="Addison-Wesley Professional" width="150" height="25" border="0" /></a></div>

	</div>

	<div id="simpleSearch"><div class="containerCenter"><form name="searchform" id="search" method="POST" action="/search/search.asp"><label for="searchstring">Search for:</label><input onfocus="showHideLayers('searchOptions','','show');checkClear(this,'Search');" id="searchstring" type="text" name="query" value="Search" /><input type="hidden" name="size" value="10" /><input type="hidden" name="docstart" value="1" /><input id="searchbutton" name="imageField" type="image" src="/display/addison-wesley/images/topnav/simplesearch/search.gif" alt="Search" /><div id="searchOptions"><select id="searchtype" name="filter"><option value="" selected="selected">Entire Site</option><option value="url &lt;contains&gt; '*authors*'">Authors</option><option value="url &lt;contains&gt; '*articles*'">Chapters &amp; Articles</option><option value="url &lt;contains&gt; '*events*'">Events</option><option value="url &lt;contains&gt; '*sales*' &lt;or&gt; url &lt;contains&gt; '*market*'">Other Site Content</option><option value="url &lt;contains&gt; '*press_release*'">Press Releases</option><option value="url &lt;contains&gt; '*title*'">Products</option><option value="url &lt;contains&gt; '*promotions*'">Promotions</option></select><p><a href="/search/advanced.asp">Advanced Search</a> | <a href="/search/help.asp">Help</a><a href="javascript:showHideLayers('searchOptions','','hide')" id="close"><img src="/display/addison-wesley/images/topnav/simplesearch/search_close.gif" alt="Close" /></a></p></div></form></div>

	</div>

	<div id="navMain"><div class="containerCenter"><div id="helloObject"><p><a href="https://memberservices.informit.com/my_account/login.asp?partner=18">Log In</a> | 
					<a href="https://memberservices.informit.com/my_account/index.asp?partner=18">My Account</a> | <a href="https://memberservices.informit.com/buy.asp?partner=18">Shopping Cart</a></p></div><div class="navList"><a id="home" href="/index.asp" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('btnhome','','/display/addison-wesley/images/topnav/mainnav/home_hover.gif',1)"><img src="/display/addison-wesley/images/topnav/mainnav/home_off.gif" name="btnhome" width="54" height="33" border="0" alt="Home" /></a><a id="bookstore" href="/bookstore/index.asp"><img src="/display/addison-wesley/images/topnav/mainnav/bookstore_on.gif" name="btnbookstore" width="72" height="33" border="0" alt="Products" /></a><a id="safari" href="http://safari.awprofessional.com/" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('btnsafari','','/display/addison-wesley/images/topnav/mainnav/safari_bookshelf_hover.gif',1)"><img src="/display/addison-wesley/images/topnav/mainnav/safari_bookshelf_off.gif" name="btnsafari" width="79" height="33" border="0" alt="Safari Bookshelf" /></a><a id="authors" href="/authors/index.asp" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('btnauthors','','/display/addison-wesley/images/topnav/mainnav/authors_hover.gif',1)"><img src="/display/addison-wesley/images/topnav/mainnav/authors_off.gif" name="btnauthors" width="67" height="33" border="0" alt="Authors" /></a><a id="promotions" href="/promotions/index.asp" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('btnpromotions','','/display/addison-wesley/images/topnav/mainnav/promotions_hover.gif',1)"><img src="/display/addison-wesley/images/topnav/mainnav/promotions_off.gif" name="btnpromotions" width="87" height="33" border="0" alt="Promotions" /></a><a id="articles" href="/articles/index.asp" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('btnarticles','','/display/addison-wesley/images/topnav/mainnav/articles_hover.gif',1)"><img src="/display/addison-wesley/images/topnav/mainnav/articles_off.gif" name="btnarticles" width="85" height="33" border="0" alt="Chapters and Articles" /></a><a id="markets" href="/markets/detail.asp?st=45608" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('btnmarkets','','/display/addison-wesley/images/topnav/mainnav/markets_hover.gif',1)"><img src="/display/addison-wesley/images/topnav/mainnav/markets_off.gif" name="btnmarkets" width="85" height="33" border="0" alt="Alliances and Imprints" /></a></div></div></div><div id="navSub"><div class="containerCenter"><p><a href="/bookstore/browse.asp?b=newrelease">New Titles</a><a href="/bookstore/browse.asp?b=comingsoon">Coming Soon</a><a href="/promotions/index.asp">Current Features</a><a href="/series/index.asp">Series</a><a href="/authors/index.asp">Authors</a><a href="/search/support.asp">Book Support</a><a href="/about/help.asp">Site Help</a></p></div></div>

 		<div id="navCrumb"><div class="containerCenter"><p><a href="/index.asp" xmlns="">Home</a> &gt; <a href="/bookstore/index.asp" xmlns="">Bookstore</a> &gt; <a href="/bookstore/index.asp?st=41942" xmlns="">Operating Systems</a> &gt; <a href="/bookstore/index.asp?st=41959" xmlns="">UNIX</a>
		&gt; Programming with POSIX庐 Threads</p></div>

  			</div>

  		</div>


    		
<div id="contentAll"><script language="JavaScript">
			var count

			function init(initCount){
				count = initCount;

				if(document.getElementById){
					for(var i=0; i < count; i++){
						if(i==0){
							document.getElementById("bss" + (i+1)).style.visibility="visible";
							document.getElementById("bss" + (i+1)).style.display="block";
						}
						else{
							document.getElementById("bss" + (i+1)).style.visibility="hidden";
							document.getElementById("bss" + (i+1)).style.display="none";
						}
					}
				}
			}

			function show(index){
				if(document.getElementById){
					for(var i=0; i < count; i++){
						if(i==(index - 1)){
							document.getElementById("bss" + (i+1)).style.visibility="visible";
							document.getElementById("bss" + (i+1)).style.display="block";
						}
						else{
							document.getElementById("bss" + (i+1)).style.visibility="hidden";
							document.getElementById("bss" + (i+1)).style.display="none";
						}
					}
				}
			}
		</script><div id="contentProduct" xmlns=""><div class="rowFirst"><div id="cover"><img src="/ShowCover.asp?isbn=0201633922&amp;type=c" alt="Programming with POSIX庐 Threads" width="125" /><p><a href="/bookstore/LargeCover.asp?isbn=0201633922">View Larger Image</a></p></div><h1>Programming with POSIX庐 Threads</h1><div class="secondCol"><div id="buy"><div class="rowFirst"><div id="tier"><p><strong><a href="https://memberservices.informit.com/my_account/login.asp?r=http%3a%2f%2fwww.awprofessional.com%2fbookstore%2fproduct.asp%3fisbn%3d0201633922%26rl%3d1">Join our site today</a></strong><br /><span class="tierJoin">for exclusive benefits</span><br /><span class="tierJoin">and savings up to 30%*</span></p></div><div id="cartButton"><a href="/buy.asp?isbn=0201633922"><img src="/display/Addison-Wesley/images/buttons/addtocart.gif" /></a><p>Usually ships in 24 hours.</p></div><div class="clear"></div></div><div id="price"><table><tr><td rowspan="2" class="message"><strong>Your current savings is 10%</strong></td><td class="price listprice">List Price:</td><td class="price listprice">$54.99</td></tr><tr><td class="price yourprice">Your Price:</td><td class="price yourprice">$49.49</td></tr><tr><td>* Discounts available on select titles only</td></tr></table></div></div><div id="freeShip"><p><a href="/cart/ordering.asp"><img src="/display/common/images/icons/shipping_16.gif" alt="Free Shipping" width="16" height="16" /></a><strong><em>Free</em> FedEx Ground Shipping</strong> No minimum purchase<br /><a href="/cart/ordering.asp">See details</a>.</p></div></div><div class="firstCol"><div id="prodInfo"><ul><li>By <a href="/authors/bio.asp?a=33a48ef9-a3e3-448c-9c8e-5d91c26ace87">David R. Butenhof</a>, <a href="/authors/bio.asp?a=2e0a1f84-1ef2-4315-a853-b15c5928703e">David R. Butenhof</a>.</li><li>Published by <a href="http://www.awprofessional.com/">Addison Wesley Professional</a>.</li><li>Series: <a href="/series/series.asp?ser=334583">Addison-Wesley Professional Computing Series</a>.</li></ul></div><p class="save"><img src="/display/common/images/icons/save_16.gif" alt="Save to My Account" /><a href="javascript:;" onclick="openBrWindow('/my_account/addTo.asp?i=0201633922','addMyAccount','scrollbars=no,resizable=yes,width=300,height=200')">Save to My Account</a></p><div id="biblio"><p>ISBN-10: 0-201-63392-2; ISBN-13: 978-0-201-63392-4; Published: May 16, 1997; Copyright 1997;
					Dimensions 7-3/8x9-1/4; Pages: 400; 
    Edition: 1st.
	</p></div><div id="requestReview"><p>Request an <a href="http://vig.prenhall.com/ec?ISBN=978-0-201-63392-4">Instructor</a> or <a href="/bookstore/media_review.asp">Media</a> review copy</p><p><a href="/bookstore/sales.asp">Corporate, Academic, and Employee Purchases</a></p><p><a href="/bookstore/sales.asp">International Buying Options</a></p></div><div class="clear"></div></div><div class="clear"></div></div><div class="rowSecond"><div class="secondCol"><div class="adBSA"><script type="text/JavaScript" language="JavaScript1.1" src="http://ad.doubleclick.net/adj/addisonwesley/Bookstore;abr=!webtv;cat=unix;cat=operating_systems;sz=336x280;tile=3;ord=91?"></script><script type="text/JavaScript" language="JavaScript1.1"><!--if ((!document.images &&navigator.userAgent.indexOf('Mozilla/2.') >= 0)  ||navigator.userAgent.indexOf("WebTV")>= 0) {  document.write('<a href="http://ad.doubleclick.net/jump/addisonwesley/Bookstore;cat=unix;cat=operating_systems;sz=336x280;tile=3;ord=91?">');document.write('<img src="http://ad.doubleclick.net/ad/addisonwesley/Bookstore;cat=unix;cat=operating_systems;sz=336x280;tile=3;ord=91?" border="0" height="280" width="336" alt="Advertisement" /></a>')}--></script> <noscript><a href="http://ad.doubleclick.net/jump/addisonwesley/Bookstore;cat=unix;cat=operating_systems;sz=336x280;tile=3;ord=91?"><img src="http://ad.doubleclick.net/ad/addisonwesley/Bookstore;cat=unix;cat=operating_systems;sz=336x280;tile=3;ord=91?" border="0" height="280" width="336" alt="Advertisement" /></a></noscript></div><div class="adSky"><script language="JavaScript1.1" type="text/JavaScript" src="http://ad.doubleclick.net/adj/addisonwesley/Bookstore;abr=!webtv;cat=unix;cat=operating_systems;abr=!webtv;sz=120x600;tile=2;ord=91?"></script><script language="JavaScript1.1" type="text/JavaScript"><!--if ((!document.images &&navigator.userAgent.indexOf('Mozilla/2.') >= 0)  ||navigator.userAgent.indexOf("WebTV")>= 0) {  document.write('<a href="http://ad.doubleclick.net/jump/addisonwesley/Bookstore;cat=unix;cat=operating_systems;sz=120x600;tile=2;ord=91?">');document.write('<img src="http://ad.doubleclick.net/ad/addisonwesley/Bookstore;cat=unix;cat=operating_systems;sz=120x600;tile=2;ord=91?" border="0" height="600" width="120" alt="Advertisement" /></a>')}--></script><noscript><a href="http://ad.doubleclick.net/jump/Bookstore;cat=unix;cat=operating_systems;sz=120x600;tile=2;ord=91?"><img src="http://ad.doubleclick.net/ad/addisonwesley/Bookstore;cat=unix;cat=operating_systems;sz=120x600;tile=2;ord=91?" border="0" height="600" width="120" alt="Advertisement" /></a></noscript></div><div class="skyArea"><div class="relateArticles prodlist"><h3>Related Articles</h3><dl><dt><a href="/articles/article.asp?p=99035" class="title">Variables and Parameters in the Korn Shell</a></dt><dd>By <a href="/authors/bio.asp?a=6cfcdff0-1c15-4ac8-bc9c-69a267c4f9dc">Anatole Olczak</a>.</dd><dd>Jul 25, 2003</dd><dt><a href="/articles/article.asp?p=99706" class="title">Advanced Programming in the UNIX&reg; Environment: UNIX File I/O</a></dt><dd>By <a href="/authors/bio.asp?a=d42c1655-d4a9-4b6f-9114-30f4262be9e8">Richard Stevens</a>.</dd><dd>Aug 1, 2003</dd><dt><a href="/articles/article.asp?p=169505" class="title">UNIX Network Programming: Sockets Introduction</a></dt><dd>By <a href="/authors/bio.asp?a=afd4ad2e-42f5-40dc-b7ec-1f4a522024fa">Andrew M. Rudoff</a>, <a href="/authors/bio.asp?a=0433872d-7e33-4514-a10b-aa5863cd662f">Bill Fenner</a>, <a href="/authors/bio.asp?a=2021c3ba-3c4c-478a-a8ef-8251e39f2d4a">W. Richard Stevens</a>.</dd><dd>Feb 27, 2004</dd></dl></div><div class="similarBooks prodlist"><h3>You May Also Like</h3><dl><dt><a href="/title/0201633825" class="title">Accelerating AIX: Performance Tuning for Programmers and Systems Administrators</a></dt><dd>By <a href="/authors/bio.asp?a=2c51c978-7095-4746-b080-a14adc65b1d1">Rudy Chukran</a>.</dd><dd>ISBN-13: 978-0-201-63382-5</dd><dd>Mar 20, 1998</dd><dd>$49.49
			(Save 10%)
		</dd></dl><dl><dt><a href="/title/0131429019" class="title">Art of UNIX Programming, The</a></dt><dd>By <a href="/authors/bio.asp?a=24a13869-850c-4cc5-91b2-a0f42666d28d">Eric S. Raymond</a>.</dd><dd>ISBN-13: 978-0-13-142901-7</dd><dd>Sep 23, 2003</dd><dd>$35.99
			(Save 10%)
		</dd></dl><dl><dt><a href="/title/0131411543" class="title">Advanced UNIX Programming, 2nd Edition</a></dt><dd>By <a href="/authors/bio.asp?a=afac0a13-a141-47d6-b508-04a03d7b4634">Marc J. Rochkind</a>.</dd><dd>ISBN-13: 978-0-13-141154-8</dd><dd>Apr 29, 2004</dd><dd>$44.99
			(Save 10%)
		</dd></dl></div><div class="similarOnline prodlist"><h3>Safari Bookshelf Titles</h3><dl><dt><a href="http://safari.awprofessional.com/0131429019" class="title">Art of UNIX Programming, The</a></dt><dd>By <a href="/authors/bio.asp?a=24a13869-850c-4cc5-91b2-a0f42666d28d">Eric S. Raymond</a>.</dd><dd>Sep 23, 2003</dd></dl><dl><dt><a href="http://safari.awprofessional.com/0201674726" class="title">LINUX & UNIX Shell Programming</a></dt><dd>By <a href="/authors/bio.asp?a=647d173a-1a34-4e39-b8fd-d2860317a0be">David Tansley</a>.</dd><dd>Dec 27, 1999</dd></dl><dl><dt><a href="http://safari.awprofessional.com/0321356403" class="title">Moving to Linux, Second Edition: Kiss the Blue Screen of Death Goodbye!, 2nd Edition</a></dt><dd>By <a href="/authors/bio.asp?a=f1653335-9afb-4e59-bfc9-48cc44a85e0f">Marcel Gagn茅</a>, <a href="/authors/bio.asp?a=c60375dd-935a-4ad9-9c25-20e873582a40">Marcel Gagn茅</a>.</dd><dd>Aug 1, 2005</dd></dl></div></div></div><div class="firstCol"><div id="moreInfo"><h2>More Information</h2><a id="info1"></a><table><tr><td><a href="#info1" onClick="show(1)">Book Description</a></td><a id="info2"></a><td><a href="#info2" onClick="show(2)">Table of Contents</a></td><a id="info3"></a><td><a href="#info3" onClick="show(3)">Preface</a></td><a id="info4"></a><td><a href="#info4" onClick="show(4)">Source Code</a></td></tr><a id="info5"></a><tr><td><a href="#info5" onClick="show(5)">Errata</a></td><td/><td/><td/></table></div><div id="prodContent"><div id="hepm"><div id="bss1"><h3>Book Description</h3><p><P> With this practical book, you will attain a solid understanding of threads and  will discover how to put this powerful mode of programming to work in real-world  applications. </P>    <P> The primary advantage of threaded programming is that it enables your  applications to accomplish more than one task at the same time by using the  number-crunching power of multiprocessor parallelism and by automatically  exploiting I/O concurrency in your code, even on a single processor machine.  The result: applications that are faster, more responsive to users, and often  easier to maintain. Threaded programming is particularly well suited to network  programming where it helps alleviate the bottleneck of slow network I/O. </P>    <P> This book offers an in-depth description of the IEEE operating system  interface standard, POSIXAE (Portable Operating System Interface) threads,  commonly called Pthreads. Written for experienced C programmers, but assuming  no previous knowledge of threads, the book explains basic concepts such as  asynchronous programming, the lifecycle of a thread, and synchronization.  You then move to more advanced topics such as attributes objects,  thread-specific data, and realtime scheduling. An entire chapter is devoted  to "real code," with a look at barriers, read/write locks, the work queue  manager, and how to utilize existing libraries. In addition, the book  tackles one of the thorniest problems faced by thread programmers-debugging-with  valuable suggestions on how to avoid code errors and performance problems  from the outset. </P>    <P> Numerous annotated examples are used to illustrate real-world concepts.  A Pthreads mini-reference and a look at future standardization are also  included. </P> <br><br> 0201633922B04062001</p></div></div><div id="hepm"><div id="bss2"><h3>Table of Contents</h3><p><br> <br> <b>List of Example Programs.</b> <br> <br> <br> <b>Preface.</b> <br> <br> <br> <b>Intended Audience.</b> <br> <br> <br> <b>About the Author.</b> <br> <br> <br> <b>Acknowledgments.</b> <br> <br> <br> <b>1. Introduction.</b> <br> <p>    <div STYLE="margin-left: 0.2in;">The "Bailing Programmers".</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Definitions and Terminology.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Asynchronous.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Concurrency.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Uniprocessor and Multiprocessor.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Parallelism.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Thread Safety and Reentrancy.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Concurrency Control Functions.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Asynchronous Programming is Intuitive...</div> </p> <p>    <div STYLE="margin-left: 0.2in;">. . . Because Unix is Asynchronous.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">. . . Because the World is Asynchronous.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">About the Examples in This Book.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Asynchronous Programming, by Example.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">the Baseline, Synchronous Version.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">A Version Using Multiple Processes.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">A Version Using Multiple Threads.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Summary.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Benefits of Threading.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Parallelism.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Concurrency.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Programming Model.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Costs of Threading.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Computing Overhead.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Programming Discipline.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Harder to Debug.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">To Thread or Not to Thread?</div> </p> <p>    <div STYLE="margin-left: 0.2in;">POSIX Thread Concepts.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Architectural Overview.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Types and Interfaces.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Checking for Errors.</div> </p> <br> <br> <b>2. Threads.</b> <br> <p>    <div STYLE="margin-left: 0.2in;">Creating and Using Threads.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">The Life of a Thread.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Creation.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Startup.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Running and Blocking.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Termination.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Recycling.</div> </p> <br> <br> <b>3. Synchronization.</b> <br> <p>    <div STYLE="margin-left: 0.2in;">Invariants, Critical Sections, and Predicates.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Mutexes.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Creating and Destroying a Mutex.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Locking and Unlocking a Mutex.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Nonblocking Mutex Locks.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Using Mutexes for Atomicity.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Sizing a Mutex to Fit the Job.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Using More Than One Mutex.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Lock Hierarchy.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Lock Chaining.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Condition Variables.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Creating and Destroying a Condition Variable.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Waiting on a Condition Variable.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Waking Condition Variable Waiters.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">One Final Alarm Program.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Memory Visibility Between Threads.</div> </p> <br> <br> <b>4. A Few Ways to Use Threads.</b> <br> <p>    <div STYLE="margin-left: 0.2in;">Pipeline.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Work Crew.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Client/Server.</div> </p> <br> <br> <b>5. Advanced Threaded Programming.</b> <br> <p>    <div STYLE="margin-left: 0.2in;">One-Time Initialization.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Attributes Objects.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Mutex Attributes.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Condition Variable Attributes.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Thread Attributes.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Cancellation.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Deferred Cancelability.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Asynchronous Cancelability.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Cleaning Up.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Thread-Specific Data.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Creating Thread-Specific Data.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Using Thread-Specific Data.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Using Destructor Functions.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Realtime Scheduling.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">POSIX Realtime Options.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Scheduling Policies and Priorities.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Contention Scope and Allocation Domain.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Problems With Realtime Scheduling.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Priority-Aware Mutexes.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Priority Ceiling Mutexes.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Priority Inheritance Mutexes.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Threads and Kernel Entities.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Many-to-One (User Level).</div> </p> <p>    <div STYLE="margin-left: 0.2in;">One-to-One (Kernel Level).</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Many-to-Few (Two Level).</div> </p> <br> <br> <b>6. Posix Adjusts to Threads.</b> <br> <p>    <div STYLE="margin-left: 0.2in;">Fork.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Fork Handlers.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Exec.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Process Exit.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Stdio.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Flockfile and Funlockfile.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Getchar_Unlocked and Putchar_Unlocked.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Thread-Safe Functions.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">User and Terminal Identification.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Directory Searching.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">String Token.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Time Representation.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Random Number Generation.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Group and User Database.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Signals.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Signal Actions.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Signal Masks.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Pthread_Kill.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Sigwait and Sigwaitinfo.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Sigev_Thread.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Semaphores: Synchronizing With a Signal-Catching Function.</div> </p> <br> <br> <b>7. "Real Code".</b> <br> <p>    <div STYLE="margin-left: 0.2in;">Extended Synchronization.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Barriers.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Read-Write Locks.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Work Queue Manager.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">But What About Existing Libraries?</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Modifying Libraries to Be Thread-Safe.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Living With Legacy Libraries.</div> </p> <br> <br> <b>8. Hints to Avoid Debugging.</b> <br> <p>    <div STYLE="margin-left: 0.2in;">Avoiding Incorrect Code.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Avoid Relying on "Thread Inertia".</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Never Bet Your Mortgage on a Thread Race.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Cooperate to Avoid Deadlocks.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Beware of Priority Inversion.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Never Share Condition Variables Between Predicates.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Sharing Stacks and Related Memory Corrupters.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Avoiding Performance Problems.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Beware of Concurrent Serialization.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Use the Right Number of Mutexes.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Too Many Mutexes Will Not Help.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Never Fight Over Cache Lines.</div> </p> <br> <br> <b>9. Posix Threads Mini-Reference.</b> <br> <p>    <div STYLE="margin-left: 0.2in;">POSIX 1003.1cn1995 Options.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">POSIX 1003.1cn1995 Limits.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">POSIX 1003.1cn1995 Interfaces.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Error Detection and Reporting.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Use of Void* Type.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Threads.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Mutexes.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Condition Variables.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Cancellation.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Thread-Specific Data.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Realtime Scheduling.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Fork Handlers.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Stdio.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Thread-Safe Functions.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Signals.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Semaphores.</div> </p> <br> <br> <b>10. Future Standardization.</b> <br> <p>    <div STYLE="margin-left: 0.2in;">X/Open Xsh5 [Unix98].</div> </p> <p>    <div STYLE="margin-left: 0.2in;">POSIX Options for XSH5.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Mutex Type.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Set Concurrency Level.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Stack Guard Size.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Parallel I/O.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Cancellation Points.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">POSIX 1003.1j.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Barriers.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Read-Write Locks.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Spinlocks.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Condition Variable Wait Clock.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Thread Abort.</div> </p> <p>    <div STYLE="margin-left: 0.2in;">Posix 1003.14.</div> </p> <br> <br> <b>Bibliography.</b> <br> <br> <br> <b>Thread Resources on the Internet.</b> <br> <br> <br> <b>Index. 0201633922T04062001</b> <br></p></div></div><div id="hepm"><div id="bss3"><h3>Preface</h3><p><P><B> The White Rabbit put on his spectacles,<BR> "Where shall I begin, please your Majesty?" he asked.<BR> "Begin at the beginning," the King said, very gravely,<BR> "and go on till you come to the end: then stop."</B><BR> &nbsp***<CODE>-</CODE>Lewis Carroll, Alice's Adventures in Wonderland<BR> </P> <BR>  <P> This book is about "threads" and how to use them. "Thread" is just a name  for a basic software "thing" that can do work on a computer. A thread is  smaller, faster, and more maneuverable than a traditional process. In  fact, once threads have been added to an operating system, a "process"  becomes just data--address space, files, and so forth--plus one or more  threads that do something with all that data. </P>   <P> With threads, you can build applications that utilize system resources  more efficiently, that are more friendly to users, that run blazingly fast  on multiprocessors, and that may even be easier to maintain. To accomplish  all this, you need only add some relatively simple function calls to your  code, adjust to a new way of thinking about programming, and leap over a  few yawning chasms. Reading this book carefully will, I hope, help you to  accomplish all that without losing your sense of humor. </P>   <P> The threads model used in this book is commonly called "Pthreads," or  "POSIX threads." Or, more formally (since you haven't yet been properly  introduced), the POSIX 1003.1cn1995 standard. I'll give you a few other  names later<CODE>-</CODE>but for now, "Pthreads" is all you need to worry about. </P>  <P>As I write this, Sun's Solaris, Digital's Digital UNIX, and SGI's IRIX  already support Pthreads. The other major commercial UNIX operating  systems will soon have Pthreads as well, maybe even by the time you read  this, including IBM's AIX and Hewlett-Packard's HP-UX. Pthreads  implementations are also available for Linux and other UNIX operating  systems. </P>   <P> In the personal computer market, Microsoft's Win32 API (the primary  programming interface to both Windows NT and Windows 95) supports threaded  programming, as does IBM's OS/2. These threaded programming models are  quite different from Pthreads, but the important first step toward using  them productively is understanding concurrency, synchronization, and  scheduling. The rest is (more or less) a matter of syntax and style, and  an experienced thread programmer can adapt to any of these models. </P>  <P> The threaded model can be (and has been) applied with great success to a  wide range of programming problems. Here are just a few: </P>  <UL> <LI>Large scale, computationally intensive programs <LI>High-performance application programs and library code that can take  advantage of multiprocessor systems <LI>Library code that can be used by threaded application programs <LI>Realtime application programs and library code <LI>Application programs and library code that perform I/O to slow external  devices (such as networks and human beings). </UL> <H3>Intended audience</H3>   <P> This book assumes that you are an experienced programmer, familiar with  developing code for an operating system in "the UNIX family" using the  ANSI C language. I have tried not to assume that you have any experience  with threads or other forms of asynchronous programming. The Introduction  chapter provides a general overview of the terms and concepts you'll need  for the rest of the book. If you don't want to read the Introduction  first, that's fine, but if you ever feel like you're "missing something"  you might try skipping back to get introduced. </P>   <P> Along the way you'll find examples and simple analogies for everything. In  the end I hope that you'll be able to continue comfortably threading along  on your own. Have fun, and "happy threading." </P>   <H3>About the author</H3>   <P> I have been involved in the Pthreads standard since it began, although I  stayed at home for the first few meetings. I was finally forced to spend a  grueling week in the avalanche-proof concrete bunker at the base of  Snowbird ski resort in Utah, watching hard-working standards  representatives from around the world wax their skis. This was very  distracting, because I had expected a standards meeting to be a formal and  stuffy environment. As a result of this misunderstanding, I was forced to  rent ski equipment instead of using my own. </P>   <P> After the Pthreads standard went into balloting, I worked on additional  thread synchronization interfaces and multiprocessor issues with several  POSIX working groups. I also helped to define the Aspen threads  extensions, which were fast-tracked into X/Open XSH5. </P>   <P> I have worked at Digital Equipment Corporation for (mumble, mumble) years,  in various locations throughout Massachusetts and New Hampshire. I was one  of the creators of Digital's own threading architecture, and I designed  (and implemented much of) the Pthreads interfaces on Digital UNIX 4.0. I  have been helping people develop and debug threaded code for more than  eight years. </P>   <P> My unofficial motto is "Better Living Through Concurrency." Threads are  not sliced bread, but then, we're programmers, not bakers, so we do what  we can. </P>   <H3>Acknowledgments</H3>   <P> This is the part where I write the stuff that I'd like to see printed, and  that my friends and coworkers want to see. You probably don't care, and I  promise not to be annoyed if you skip over it<CODE>-</CODE>nbut if you're curious, by  all means read on. </P>   <P> No project such as this book can truly be accomplished by a single person,  despite the fact that only one name appears on the cover. I could have  written a book about threads without any help<CODE>-</CODE>I know a great deal about  threads, and I am at least reasonably competent at written communication.  However, the result would not have been this book, and this book is better  than that hypothetical work could possibly have been. </P>   <P> Thanks first and foremost to my manager Jean Fullerton, who gave me the  time and encouragement to write this book on the job<CODE>-</CODE>and thanks to the  rest of the DECthreads team who kept things going while I wrote, including  Brian Keane, Webb Scales, Jacqueline Berg, Richard Love, Peter Portante,  Brian Silver, Mark Simons, and Steve Johnson. </P>   <P> Thanks to Garret Swart who, while he was with Digital at the Systems  Research Center, got us involved with POSIX. Thanks to Nawaf Bitar who  worked with Garret to create, literally overnight, the first draft of what  became Pthreads, and who became POSIX thread evangelist through the  difficult period of getting everyone to understand just what the heck this  threading thing was all about anyway. Without Garret, and especially  Nawaf, Pthreads might not exist, and certainly wouldn't be as good as it  is. (The lack of perfection is not their responsibility<CODE>-</CODE>that's the way  life is.) </P>   <P> Thanks to everyone who contributed to the design of cma, Pthreads, UNIX98,  and to the users of DCE threads and DECthreads, for all the help,  thought-provoking discourse, and assorted skin-thickening exercises,  including Andrew Birrell, Paul Borman, Bob Conti, Bill Cox, Jeff Denham,  Peter Gilbert, Rick Greer, Mike Grier, Kevin Harris, Ken Hobday, Mike  Jones, Steve Kleiman, Bob Knighten, Leslie Lamport, Doug Locke, Paula  Long, Finnbarr P. Murphy, Bill Noyce, Simon Patience, Harold Seigel, Al  Simons, Jim Woodward, and John Zolnowsky. </P>   <P> Many thanks to all those who patiently reviewed the drafts of this book  (and even to those who didn't seem so patient at times). Brian Kernighan,  Rich Stevens, Dave Brownell, Bill Gallmeister, Ilan Ginzburg, Will Morse,  Bryan O'Sullivan, Bob Robillard, Dave Ruddock, Bil Lewis, and many others  suggested or motivated improvements in structure and detail<CODE>-</CODE>and provided  additional skin-thickening exercises to keep me in shape. Devang Shah and  Bart Smaalders answered some Solaris questions, and Bryan O'Sullivan  suggested what became the "bailing programmers" analogy. </P>   <P> Thanks to John Wait and Lana Langlois at Addison Wesley Longman, who  waited with great patience as a first-time writer struggled to balance  writing a book with engineering and consulting commitments. Thanks to  Pamela Yee and Erin Sweeney, who managed the book's production process,  and to all the team (many of whose names I'll never know), who helped. Thanks to my wife, Anne Lederhos, and our daughters Amy and Alyssa, for  all the things for which any writers may thank their families, including  support, tolerance, and just being there. And thanks to Charles Dodgson  (Lewis Carroll), who wrote extensively about threaded programming (and  nearly everything else) in his classic works Alice's Adventures in  Wonderland, Through the Looking-Glass, and The Hunting of the Snark. </P>   <ADDRESS> Dave Butenhof<BR> Digital Equipment Corporation<BR> 110 Spit Brook Road, ZKO2-3/Q18<BR> Nashua, NH 03062<BR> butenhof@zko.dec.com<BR> December 1996 </ADDRESS>  <br><br> 0201633922P04062001 </UL></p></div></div><div id="hepm"><div id="bss4"><h3>Source Code</h3><p>
<P>Click below for Source Code related to this title: </P>
<P>This file contains all individual code files zipped together:<br>
  <a href="../content/images/0201633922/sourcecode/programs.tar.z">program.tar.Z</a></P>
<P>Individual Files:<br>
  <a href="../content/images/0201633922/sourcecode/alarm.c">alarm.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/alarm_cond.c">alarm_cond.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/alarm_fork.c">alarm_fork.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/alarm_mutex.c">alarm_mutex.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/alarm_thread.c">alarm_thread.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/atfork.c">atfork.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/backoff.c">backoff.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/barrier.c">barrier.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/barrier.h">barrier.h</a></P>
<P><a href="../content/images/0201633922/sourcecode/barrier_main.c">barrier_main.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/cancel.c">cancel.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/cancel_async.c">cancel_async.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/cancel.c">cancel_cleanup.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/cancel_disable.c">cancel_disable.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/cancel_subcontract.c">cancel_subcontract.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/cond.c">cond.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/cond_attr.c">cond_attr.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/cond_dynamic.c">cond_dynamic.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/crew.c">crew.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/errors.h">errors.h</a></P>
<P><a href="../content/images/0201633922/sourcecode/flock.c">flock.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/getlogin.c">getlogin.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/hello.c">hello.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/inertia.c">inertia.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/lifecycle.c">lifecycle.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/Makefile">Makefile</a></P>
<P><a href="../content/images/0201633922/sourcecode/mutex_attr.c">mutex_attr.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/mutex.dynamic.c">mutex_dynamic.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/mutex.static.c">mutex_static.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/once.c">once.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/pipe.c">pipe.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/putchar.c">putchar.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/README">README</a></P>
<P><a href="../content/images/0201633922/sourcecode/rwlock.c">rwlock.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/rwlock.h">rwlock.h</a></P>
<P><a href="../content/images/0201633922/sourcecode/rwlock_try_main.c">rwlock_try_main.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/sched_attr.c">sched_attr.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/sched_thread.c">sched_thread.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/semaphore_signal.c">semaphore_signal.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/semaphore_wait.c">semaphore_wait.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/server.c">server.c</a></P>
<P><a href="../content/images/0201633922/sourcecode/sigev_thread.c">sigev_thread.c</a></P>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?