没有合适的资源?快使用搜索试试~ 我知道了~
经典的多线程编程教程,值得下载看一看。
资源推荐
资源详情
资源评论
Programming with POSIX Threads
David R. Butenhof
ADDISON-WESLEY
An Imprint of Addison Wesley Longman, Inc.
Reading, Massachusetts · Harlow, England · Menlo Park, California
Berkeley, California · Don Mills, Ontario · Sydney
Bonn · Amsterdam · Tokyo · Mexico City
Trademark acknowledgments:
UNIX is a registered trademark in the United States and other countries, licensed exclusively
through X/Open Company Ltd. Digital, DEC, Digital UNIX, DECthreads, VMS, and OpenVMS
are trademarks of Digital Equipment Corporation. Solaris, SPARC, SunOS, and Sun are
trademarks of Sun Microsystems Incorporated. SGI and IRIX are trademarks of Silicon Graphics,
Incorporated. HP-UX is a trademark of Hewlett-Packard Company. AIX, IBM, and OS/2 are
trademarks or registered trademarks of the IBM Corporation. X/Open is a trademark of X/Open
Company Ltd. POSIX is a registered trademark of the Institute of Electrical and Electronics
Engineers, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in this book and Addison-Wesley was
aware of a trademark claim, the designations have been printed in initial caps or all caps.
The authors and publishers have taken care in the preparation of this book, but make no expressed
or implied warranty of any kind and assume no responsibility for errors or omissions. No liability
is assumed for incidental or consequential damages in connection with or arising out of the use of
the information or programs contained herein.
The publisher offers discounts on this book when ordered in quantity for special sales.
For more information, please contact:
Corporate & Professional Publishing Group
Addison-Wesley Publishing Company
One Jacob Way
Reading, Massachusetts 01867
Library of Congress Cataloging-in-Publication Data
Butenhof, David R., 1956-
Programming with POSIX threads / David R. Butenhof. p. cm. -- (Addison-Wesley
professional computing series). Includes bibliographical references and index.
ISBN 0-201-63392-2 (pbk.)
1. Threads (Computer programs) 2. POSIX (Computer software standard) 3. Electronic
digital computers--Programming. I. Title. II. Series.
QA76.76.T55B88 1997
005.4'32--dc21
97-6635
CIP
Copyright 1997 by Addison Wesley Longman, Inc.
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or
transmitted, in any form, or by any means, electronic, mechanical. photocopying, recording, or
otherwise, without the prior consent of the publisher. Printed in the United States of America.
Published simultaneously in Canada.
Text printed on recycled and acid-free paper.
23456789 MA 00999897
2nd Printing October, 1997
To Anne, Amy,
and
Alyssa.
Quote acknowledgment:
American Heritage Dictionary of the English Language: page 1.
ISO/IEC 9945-1:1996, ?1996 by IEEE: page 29.
Lewis Carroll, Alice's Adventures in Wonderland: pages xv, 47, 70, 88, 97, 98, 106, 131, 142,
161, 189, 197. Reproduced by permission of Macmillan Children's Books.
Lewis Carroll, Through the Looking-Glass: pages 1, 4, 8, 20, 25, 29, 35, 45, 172, 214, 241,283,
290, 302. Reproduced by permission of Macmillan Children's Books.
Lewis Carroll, The Hunting of the Snark pages 3, 13, 28, 39, 120, 131, 134, 289, 367. Reproduced
by permission of Macmillan Children's Books.
Preface
_______________________________________________________________________________
The White Rabbit put on his spectacles,
"Where shall I begin, please your Majesty?" he asked.
"Begin at the beginning," the King said, very gravely,
"and go on till you come to the end: then stop."
--Lewis Carroll, Alice's Adventures in Wonderland
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.
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.
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. lc-1995
standard. I'll give you a few other names later--but for now, "Pthreads" is all you need to worry
about.
Pthreads interfaces are included with Sun's Solaris; Hewlett-Packard's Tru64 UNIX,
OpenVMS, NonStop platform, and HP-UX; IBM's AIX, OS/400, and OS/390; SGI's IRIX; SCO's
UnixWare; Apple's Mac OS X; and Linux (any major distribution). There's even an Open Source
emulation package that allows you to use portable Pthread interfaces on Win32 systems.
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.
The threaded model can be (and has been) applied with great success to a wide range of
programming problems. Here are just a few:
Large scale, computationally intensive programs
High-performance application programs and library code that can take advantage of
multiprocessor systems
Library code that can be used by threaded application programs
Realtime application programs and library code
Application programs and library code that perform I/O to slow external devices (such
as networks and human beings).
Intended audience
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.
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."
About the author
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.
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.
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.
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.
Acknowledgments
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 but if you're curious, by all means read on.
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--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.
Thanks first and foremost to my manager Jean Fullerton, who gave me the time and
encouragement to write this book on the job--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.
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
剩余201页未读,继续阅读
资源评论
mingjingx
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于yolov5识别算法实现的DNF自动脚本源码.zip
- 基于Python实现的自动化办公项目.zip
- 基于python实现的基于PyQt5和爬虫的小说阅读系统.zip
- 机械设计整经机上纱自动化sw20非常好的设计图纸100%好用.zip
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功