没有合适的资源?快使用搜索试试~ 我知道了~
pthread primer
需积分: 19 21 下载量 69 浏览量
2007-07-19
16:35:37
上传
评论
收藏 952KB PDF 举报
温馨提示
试读
370页
it is about how to use pthread in linux program with c
资源推荐
资源详情
资源评论
1
PThreads Primer
A Guide to Multithreaded Programming
Bil Lewis
Daniel J. Berg
SunSoft Press
A Prentice Hall Title
1996 Sun Microsystems, Inc. — Printed in the United States of America.
2550 Garcia Avenue, Mountain View, California 94043-1100 U.S.A.
All rights reserved. This book is protected by copyright and distributed under licenses
restricting its use, copying, distribution, and decompilation. No part of this book may be
reproduced in any form by any means without prior written authorization of Sun and its
licensors, if any.
Portions of the products described in this book may be derived from the UNIX
®
and Berkeley
4.3 BSD systems, licensed from UNIX System Laboratories, Inc., a wholly owned subsidiary
of Novell, Inc., and the University of California, respectively. Third-party font software in
this product is protected by copyright and licensed from Sun’s font suppliers.
RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the United States
government is subject to restrictions as set forth in DFARS 252.227-7013 (c)(1)(ii) and FAR
52.227-19.
The products described in this book may be protected by one or more U.S. patents, foreign
patents, or pending applications.
TRADEMARKS— Sun, Sun Microsystems, the Sun logo, SunSoft, Solaris, Solaris Sunburst
Design, OpenWindows, ONC, ONC+, SunOS, AnswerBook, Sun FORTRAN, Wabi, ToolTalk,
NFS, XView, SunView, and The Network is the Computer are trademarks or registered
trademarks of Sun Microsystems, Inc. UNIX is a registered trademark in the United States
and other countries exclusively licensed through X/Open Company, Ltd. OPEN LOOK® is a
registered trademark of Novell, Inc. Adobe, PostScript, Display PostScript, and PhotoShop
are trademarks or registered trademarks of Adobe Systems Incorporated. PowerPC is a
trademark of International Business Machines Corporation. Xenix, Microsoft Windows, and
Windows NT are trademarks or registered trademarks of Microsoft Corporation. All other
product names mentioned herein are the trademarks of their respective owners.
SuperSPARC and all SPARC trademarks, including the SCD Compliant Logo, are trademarks
or registered trademarks of SPARC International, Inc. SPARCstation, SPARCserver,
SPARCengine, SPARCworks, SPARCworks iMPact, and SPARCompiler are licensed
exclusively to Sun Microsystems, Inc. Products bearing SPARC trademarks are based upon
an architecture developed by Sun Microsystems, Inc.
The OPEN LOOK® and Sun™ Graphical User Interfaces were developed by Sun
Microsystems, Inc. for its users and licensees. Sun acknowledges the pioneering efforts of
Xerox in researching and developing the concept of visual or graphical user interfaces for the
computer industry. Sun holds a non-exclusive license from Xerox to the Xerox Graphical User
Interface, which license also covers Sun’s licensees who implement OPEN LOOK GUIs and
otherwise comply with Sun’s written license agreements.
X Window System is a trademark of X Consortium, Inc.
The publisher offers discounts on this book when ordered in bulk quantities. For more
information, contact: Corporate Sales Department, Prentice Hall PTR, One Lake Street,
Upper Saddle River, NJ 07458. Phone: 800-382-3419 or 201-236-7156, Fax: 201-236-7141,
email: corpsales@prenhall.com
Cover designer: M & K Design, Palo Alto, California
Manufacturing manager: Alexis R. Heydt
Acquisitions editor: Gregory G. Doench
10987654321
ISBN 0-13-443698-9
SunSoft Press
A Prentice Hall Title
3
To Elaine, my wife and best friend, for her encouragement and understanding during all
the late nights and weekends when I should have been spending time with her.
Thank You!
— Dan
A mes enfants, Caleb, Matthew, et Rebecca. “Tu deviens responsable pour toujours de ce
que tu as apprivoisé”
— Bil
Dedication
4 Threads Primer
5
Acknowledgments to the Threads Primer . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Acknowledgments to the Pthreads Primer . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
2. Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Background: Traditional Operating Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
What Is a Thread? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Kernel Interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Concurrency vs. Parallelism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
System Calls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Signals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Synchronization. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Scheduling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
The Value of Using Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Parallelism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Throughput . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Responsiveness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Communications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
System Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Simplified Realtime Processing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Simplified Signal Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Distributed Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Same Binary for Uniprocessors and Multiprocessors. . . . . . . . . . . . . . . . . . 49
Program Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Single Source for Multiple Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
What Kind of Programs to Thread?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Inherently MT Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Not Obviously MT Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Automatic Threading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Programs Not to Thread. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
What About Shared Memory? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Threads Standards. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Operating Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
NFS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
SPECfp 95. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
剩余369页未读,继续阅读
资源评论
kimchulgoon
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功