<div class="article_content tracking-ad" id="article_content" style="margin:20px 0px 0px; font-size:14px; line-height:26px; font-family:Arial; color:rgb(51,51,51)">
<p style="padding:0.5em 0.2em; margin-top:0px; margin-bottom:0px; border:none; outline:none; font-family:Galdeano,'Hiragino Sans GB','Microsoft YaHei',Trebuchet,'Trebuchet MS',Tahoma,'Lucida Grande','Lucida Sans Unicode',Verdana,sans-serif; font-size:16px; line-height:24px">
最近研究<a class="replace_word" href="http://lib.csdn.net/base/mysql" rel="nofollow" style="color:rgb(223,52,52); text-decoration:none; font-weight:bold" target="_blank" title="MySQL知识库">MySQL</a>源码,各种锁,各种互斥,好在我去年认真学了《unix环境高级编程》, 虽然已经忘得差不多了,但是学过始终是学过,拿起来也快。写这篇文章的目的就是总结<a class="replace_word" href="http://lib.csdn.net/base/linux" rel="nofollow" style="color:rgb(223,52,52); text-decoration:none; font-weight:bold" target="_blank" title="Linux知识库">Linux</a> 下多线程编程,作为日后的参考资料。</p>
<p style="padding:0.5em 0.2em; margin-top:0px; margin-bottom:0px; border:none; outline:none; font-family:Galdeano,'Hiragino Sans GB','Microsoft YaHei',Trebuchet,'Trebuchet MS',Tahoma,'Lucida Grande','Lucida Sans Unicode',Verdana,sans-serif; font-size:16px; line-height:24px">
本文将介绍<a class="replace_word" href="http://lib.csdn.net/base/linux" rel="nofollow" style="color:rgb(223,52,52); text-decoration:none; font-weight:bold" target="_blank" title="Linux知识库">linux</a>系统下多线程编程中,线程同步的各种方法。包括:</p>
<ol style="padding:0px; margin:0px; border:none; outline:none; list-style-position:inside; font-family:Galdeano,'Hiragino Sans GB','Microsoft YaHei',Trebuchet,'Trebuchet MS',Tahoma,'Lucida Grande','Lucida Sans Unicode',Verdana,sans-serif; font-size:16px; line-height:24px">
<li style="padding:0.2em 0px; margin:0px; border:none; outline:none"><a href="http://mingxinglai.com/cn/2013/06/mutil-threads/#1" rel="nofollow" style="color:rgb(221,0,0); text-decoration:none; padding:0px; margin:0px; border:none; outline:none" target="_blank">互斥量(mutex)</a></li><li style="padding:0.2em 0px; margin:0px; border:none; outline:none"><a href="http://mingxinglai.com/cn/2013/06/mutil-threads/#2" rel="nofollow" style="color:rgb(221,0,0); text-decoration:none; padding:0px; margin:0px; border:none; outline:none" target="_blank">读写锁</a></li><li style="padding:0.2em 0px; margin:0px; border:none; outline:none"><a href="http://mingxinglai.com/cn/2013/06/mutil-threads/#3" rel="nofollow" style="color:rgb(221,0,0); text-decoration:none; padding:0px; margin:0px; border:none; outline:none" target="_blank">条件变量</a></li><li style="padding:0.2em 0px; margin:0px; border:none; outline:none"><a href="http://mingxinglai.com/cn/2013/06/mutil-threads/#4" rel="nofollow" style="color:rgb(221,0,0); text-decoration:none; padding:0px; margin:0px; border:none; outline:none" target="_blank">信号量</a></li><li style="padding:0.2em 0px; margin:0px; border:none; outline:none"><a href="http://mingxinglai.com/cn/2013/06/mutil-threads/#5" rel="nofollow" style="color:rgb(221,0,0); text-decoration:none; padding:0px; margin:0px; border:none; outline:none" target="_blank">文件互斥</a></li></ol>
<p style="padding:0.5em 0.2em; margin-top:0px; margin-bottom:0px; border:none; outline:none; font-family:Galdeano,'Hiragino Sans GB','Microsoft YaHei',Trebuchet,'Trebuchet MS',Tahoma,'Lucida Grande','Lucida Sans Unicode',Verdana,sans-serif; font-size:16px; line-height:24px">
在介绍不同的线程同步的方法之前,先简单的介绍一下进程和线程的概念, 它们的优缺点,线程相关的API,读者——写者问题和哲学家就餐问题。</p>
<h1 style="margin:0px; padding:0.5em 0px; border:none; outline:none; font-family:Cuprum,'Hiragino Sans GB','Microsoft YaHei',sans-serif; font-size:1.6em; line-height:24px">
<a name="t0" style="color:rgb(51,102,153)" target="_blank"></a>基础知识</h1>
<h3 style="margin:0px; padding:0.5em 0.2em; border:none; outline:none; font-family:Cuprum,'Hiragino Sans GB','Microsoft YaHei',sans-serif; font-size:1.2em; color:rgb(34,34,34); line-height:24px">
<a name="t1" style="color:rgb(51,102,153)" target="_blank"></a>1. 进程和线程</h3>
<p style="padding:0.5em 0.2em; margin-top:0px; margin-bottom:0px; border:none; outline:none; font-family:Galdeano,'Hiragino Sans GB','Microsoft YaHei',Trebuchet,'Trebuchet MS',Tahoma,'Lucida Grande','Lucida Sans Unicode',Verdana,sans-serif; font-size:16px; line-height:24px">
进程(process)是指在系统中正在运行的一个应用程序,是系统资源分配的基本单位,在内存 中有其完备的数据空间和代码空间,拥有完整的虚拟空间地址。一个进程所拥有的数据和变量只 属于它自己。</p>
<p style="padding:0.5em 0.2em; margin-top:0px; margin-bottom:0px; border:none; outline:none; font-family:Galdeano,'Hiragino Sans GB','Microsoft YaHei',Trebuchet,'Trebuchet MS',Tahoma,'Lucida Grande','Lucida Sans Unicode',Verdana,sans-serif; font-size:16px; line-height:24px">
线程(thread)是进程内相对独立的可执行单元,所以也被称为轻量进程(lightweight processes );是<a class="replace_word" href="http://lib.csdn.net/base/operatingsystem" rel="nofollow" style="color:rgb(223,52,52); text-decoration:none; font-weight:bold" target="_blank" title="操作系统知 |
|