⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 posix线程编程指南(3).htm

📁 POSIX平台多线程编程指南 通用开放式操作系统的多线程应用指南。
💻 HTM
📖 第 1 页 / 共 4 页
字号:
                      <TD vAlign=center><IMG height=16 alt="" 
                        src="Posix线程编程指南(3).files/u_bold.gif" width=16 
                        border=0><BR></TD>
                      <TD vAlign=top align=right><A class=fbox 
                        href="http://www-128.ibm.com/developerworks/cn/linux/thread/posix_threadapi/part3/#main"><B>回页首</B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
            <P><A name=4><SPAN class=atitle>异步信号</SPAN></A></P>
            <P>由于LinuxThreads是在核外使用核内轻量级进程实现的线程,所以基于内核的异步信号操作对于线程也是有效的。但同时,由于异步信号总是实际发往某个进程,所以无法实现POSIX标准所要求的"信号到达某个进程,然后再由该进程将信号分发到所有没有阻塞该信号的线程中"原语,而是只能影响到其中一个线程。</P>
            <P>POSIX异步信号同时也是一个标准C库提供的功能,主要包括信号集管理(sigemptyset()、sigfillset()、sigaddset()、sigdelset()、sigismember()等)、信号处理函数安装(sigaction())、信号阻塞控制(sigprocmask())、被阻塞信号查询(sigpending())、信号等待(sigsuspend())等,它们与发送信号的kill()等函数配合就能实现进程间异步信号功能。LinuxThreads围绕线程封装了sigaction()何raise(),本节集中讨论LinuxThreads中扩展的异步信号函数,包括pthread_sigmask()、pthread_kill()和sigwait()三个函数。毫无疑问,所有POSIX异步信号函数对于线程都是可用的。</P>
            <P>int pthread_sigmask(int how, const sigset_t *newmask, sigset_t 
            *oldmask) 
            <BR>设置线程的信号屏蔽码,语义与sigprocmask()相同,但对不允许屏蔽的Cancel信号和不允许响应的Restart信号进行了保护。被屏蔽的信号保存在信号队列中,可由sigpending()函数取出。 
            </P>
            <P>int pthread_kill(pthread_t thread, int signo) 
            <BR>向thread号线程发送signo信号。实现中在通过thread线程号定位到对应进程号以后使用kill()系统调用完成发送。 
            </P>
            <P>int sigwait(const sigset_t *set, int *sig) 
            <BR>挂起线程,等待set中指定的信号之一到达,并将到达的信号存入*sig中。POSIX标准建议在调用sigwait()等待信号以前,进程中所有线程都应屏蔽该信号,以保证仅有sigwait()的调用者获得该信号,因此,对于需要等待同步的异步信号,总是应该在创建任何线程以前调用pthread_sigmask()屏蔽该信号的处理。而且,调用sigwait()期间,原来附接在该信号上的信号处理函数不会被调用。 
            </P>
            <P>如果在等待期间接收到Cancel信号,则立即退出等待,也就是说sigwait()被实现为取消点。</P><BR>
            <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
              <TBODY>
              <TR>
                <TD><IMG height=1 alt="" 
                  src="Posix线程编程指南(3).files/blue_rule.gif" width="100%"><BR><IMG 
                  height=6 alt="" src="Posix线程编程指南(3).files/c.gif" width=8 
                  border=0></TD></TR></TBODY></TABLE>
            <TABLE class=no-print cellSpacing=0 cellPadding=0 align=right>
              <TBODY>
              <TR align=right>
                <TD><IMG height=4 alt="" src="Posix线程编程指南(3).files/c.gif" 
                  width="100%"><BR>
                  <TABLE cellSpacing=0 cellPadding=0 border=0>
                    <TBODY>
                    <TR>
                      <TD vAlign=center><IMG height=16 alt="" 
                        src="Posix线程编程指南(3).files/u_bold.gif" width=16 
                        border=0><BR></TD>
                      <TD vAlign=top align=right><A class=fbox 
                        href="http://www-128.ibm.com/developerworks/cn/linux/thread/posix_threadapi/part3/#main"><B>回页首</B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
            <P><A name=5><SPAN class=atitle>其他同步方式</SPAN></A></P>
            <P>除了上述讨论的同步方式以外,其他很多进程间通信手段对于LinuxThreads也是可用的,比如基于文件系统的IPC(管道、Unix域Socket等)、消息队列(Sys.V或者Posix的)、System 
            V的信号灯等。只有一点需要注意,LinuxThreads在核内是作为共享存储区、共享文件系统属性、共享信号处理、共享文件描述符的独立进程看待的。</P><BR>
            <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
              <TBODY>
              <TR>
                <TD><IMG height=1 alt="" 
                  src="Posix线程编程指南(3).files/blue_rule.gif" width="100%"><BR><IMG 
                  height=6 alt="" src="Posix线程编程指南(3).files/c.gif" width=8 
                  border=0></TD></TR></TBODY></TABLE>
            <TABLE class=no-print cellSpacing=0 cellPadding=0 align=right>
              <TBODY>
              <TR align=right>
                <TD><IMG height=4 alt="" src="Posix线程编程指南(3).files/c.gif" 
                  width="100%"><BR>
                  <TABLE cellSpacing=0 cellPadding=0 border=0>
                    <TBODY>
                    <TR>
                      <TD vAlign=center><IMG height=16 alt="" 
                        src="Posix线程编程指南(3).files/u_bold.gif" width=16 
                        border=0><BR></TD>
                      <TD vAlign=top align=right><A class=fbox 
                        href="http://www-128.ibm.com/developerworks/cn/linux/thread/posix_threadapi/part3/#main"><B>回页首</B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR><BR>
            <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
              <TBODY>
              <TR>
                <TD><IMG height=1 alt="" 
                  src="Posix线程编程指南(3).files/blue_rule.gif" width="100%"><BR><IMG 
                  height=6 alt="" src="Posix线程编程指南(3).files/c.gif" width=8 
                  border=0></TD></TR></TBODY></TABLE>
            <TABLE class=no-print cellSpacing=0 cellPadding=0 align=right>
              <TBODY>
              <TR align=right>
                <TD><IMG height=4 alt="" src="Posix线程编程指南(3).files/c.gif" 
                  width="100%"><BR>
                  <TABLE cellSpacing=0 cellPadding=0 border=0>
                    <TBODY>
                    <TR>
                      <TD vAlign=center><IMG height=16 alt="" 
                        src="Posix线程编程指南(3).files/u_bold.gif" width=16 
                        border=0><BR></TD>
                      <TD vAlign=top align=right><A class=fbox 
                        href="http://www-128.ibm.com/developerworks/cn/linux/thread/posix_threadapi/part3/#main"><B>回页首</B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
            <P><A name=author><SPAN class=atitle>关于作者</SPAN></A></P>
            <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
              <TBODY>
              <TR>
                <TD colSpan=3><IMG height=5 alt="" 
                  src="Posix线程编程指南(3).files/c.gif" width="100%"></TD></TR>
              <TR vAlign=top align=left>
                <TD>
                  <P></P></TD>
                <TD><IMG height=5 alt="" src="Posix线程编程指南(3).files/c.gif" 
                  width=4></TD>
                <TD width="100%">
                  <P><B>杨沙洲,</B>男,现攻读国防科大计算机学院计算机软件方向博士学位。您可以通过电子邮件 <A 
                  href="mailto:pubb@163.net">pubb@163.net</A>跟他联系。 
              </P></TD></TR></TBODY></TABLE><BR><BR>
            <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
              <TBODY>
              <TR>
                <TD><IMG height=1 alt="" 
                  src="Posix线程编程指南(3).files/blue_rule.gif" width="100%"><BR><IMG 
                  height=6 alt="" src="Posix线程编程指南(3).files/c.gif" width=8 
                  border=0></TD></TR></TBODY></TABLE>
            <TABLE class=no-print cellSpacing=0 cellPadding=0 align=right>
              <TBODY>
              <TR align=right>
                <TD><IMG height=4 alt="" src="Posix线程编程指南(3).files/c.gif" 
                  width="100%"><BR>
                  <TABLE cellSpacing=0 cellPadding=0 border=0>
                    <TBODY>
                    <TR>
                      <TD vAlign=center><IMG height=16 alt="" 
                        src="Posix线程编程指南(3).files/u_bold.gif" width=16 
                        border=0><BR></TD>
                      <TD vAlign=top align=right><A class=fbox 
                        href="http://www-128.ibm.com/developerworks/cn/linux/thread/posix_threadapi/part3/#main"><B>回页首</B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
            <P class=no-print><SPAN class=atitle><A 
            name=rate>对本文的评价</A></SPAN></P><SPAN class=no-print>
            <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
              <TBODY>
              <TR vAlign=top>
                <TD>
                  <FORM 
                  action=https://www-128.ibm.com/developerworks/secure/cnratings.jsp 
                  method=get><INPUT type=hidden value=Posix线程编程指南(3) 
                  name=ArticleTitle><INPUT type=hidden value=Linux 
                  name=Zone><INPUT type=hidden 
                  value=http://www.ibm.com/developerworks/cn/thankyou/ 
                  name=RedirectURL><INPUT type=hidden value=china 
name=localsite>
                  <SCRIPT language=javascript>document.write('<input type="hidden" name="url" value="'+location.href+'">');</SCRIPT>

                  <TABLE cellSpacing=0 cellPadding=0 border=0>
                    <TBODY>
                    <TR>
                      <TD><IMG height=8 alt="" 
                        src="Posix线程编程指南(3).files/c.gif" width=100 
                    border=0></TD></TR>
                    <TR vAlign=top>
                      <TD><INPUT type=radio value=1 name=Rating>太差! (1)</TD></TR>
                    <TR vAlign=top>
                      <TD><INPUT type=radio value=2 name=Rating>需提高 (2)</TD></TR>
                    <TR vAlign=top>
                      <TD><INPUT type=radio value=3 name=Rating>一般;尚可 
(3)</TD></TR>
                    <TR vAlign=top>
                      <TD><INPUT type=radio value=4 name=Rating>好文章 (4)</TD></TR>
                    <TR vAlign=top>
                      <TD><INPUT type=radio value=5 
                    name=Rating>真棒!(5)</TD></TR></TBODY></TABLE><BR><B>建议?</B><BR><TEXTAREA id=Comments name=Comments rows=5 wrap=virtual cols=60>&nbsp;</TEXTAREA><BR><BR><INPUT type=submit value=反馈意见></FORM></TD></TR>
              <TR vAlign=top>
                <TD bgColor=#ffffff><IMG height=8 alt="" 
                  src="Posix线程编程指南(3).files/c.gif" width=100 
              border=0></TD></TR></TBODY></TABLE></SPAN><SPAN class=no-print>
            <TABLE cellSpacing=0 cellPadding=0 align=right>
              <TBODY>
              <TR align=right>
                <TD><IMG height=8 alt="" src="Posix线程编程指南(3).files/c.gif" 
                  width="100%"><BR>
                  <TABLE cellSpacing=0 cellPadding=0 border=0>
                    <TBODY>
                    <TR>
                      <TD vAlign=center><IMG height=16 alt="" 
                        src="Posix线程编程指南(3).files/u_bold.gif" width=16 
                        border=0><BR></TD>
                      <TD vAlign=top align=right><A class=fbox 
                        href="http://www-128.ibm.com/developerworks/cn/linux/thread/posix_threadapi/part3/#main"><B>回页首</B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR></SPAN></TD>
          <TD width=10><IMG height=1 alt="" src="Posix线程编程指南(3).files/c.gif" 
            width=10></TD></TR></TBODY></TABLE>
      <P class=greytext>其他公司、产品或服务的名称可能是其他公司的商标或服务标志。</P></TD></TR></TBODY></TABLE><!--FOOTER_BEGIN--><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
    <TD class=bbg height=19>
      <TABLE cellSpacing=0 cellPadding=0 border=0>
        <TBODY>
        <TR>
          <TD><SPAN class=spacer>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><A 
            class=mainlink href="http://www.ibm.com/cn/ibm/index.shtml">关于 
            IBM</A></TD>
          <TD class=footer-divider width=27>&nbsp;&nbsp;&nbsp;&nbsp;</TD>
          <TD><A class=mainlink 
            href="http://www.ibm.com/cn/ibm/privacy/index.shtml">隐私条约</A></TD>
          <TD class=footer-divider width=27>&nbsp;&nbsp;&nbsp;&nbsp;</TD>
          <TD><A class=mainlink href="http://www.ibm.com/contact/">联系 
          IBM</A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<SCRIPT language=JavaScript1.2 src="Posix线程编程指南(3).files/stats.js" 
type=text/javascript></SCRIPT>
<NOSCRIPT><IMG height=1 alt="" 
src="E:\MyLove\资料\Posix线程编程指南\Posix线程编程指南(3).files\c(1).gif" width=1 
border=0></NOSCRIPT><!--FOOTER_END--><!--XSLT stylesheet used to transform this file:  dw-document-html-5.3.xsl--> 
</BODY></HTML>

⌨️ 快捷键说明

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