多线程,信号!!!
来源:互联网 发布:大富豪3.4.1最新源码 编辑:程序博客网 时间:2024/05/16 00:59
http://linux.die.net/man/7/pthreads
Linux implementations of POSIX threads
- Over time, two threading implementations have been provided by the GNU C library on Linux:
- LinuxThreads
- This is the original Pthreads implementation. Since glibc 2.4, this implementation is no longer supported.
- NPTL (Native POSIX Threads Library)
- This is the modern Pthreads implementation. By comparison with LinuxThreads, NPTL provides closer conformance to the requirements of the POSIX.1 specification and better performance when creating large numbers of threads.NPTL is available since glibc 2.3.2, and requires features that are present in the Linux 2.6 kernel.
- Both of these are so-called 1:1 implementations, meaning that each thread maps to a kernel scheduling entity. Both threading implementations employ the Linux clone(2) system call. In NPTL, thread synchronization primitives (mutexes, thread joining, and so on) are implemented using the Linux futex(2) system call.
NPTL 2.3.4
http://www.ibm.com/developerworks/cn/linux/l-nptl/index.html
NPTL不再像LinuxThreads那样需要使用用户级的管理线程来维护线程的创建和销毁,LinuxThreads有一个管理线程__pthread_manager
http://www.ibm.com/developerworks/cn/linux/l-threading.html
关于编写安全的信号处理函数主要有以下一些规则:
- 信号处理函数尽量只执行简单的操作,譬如只是设置一个外部变量,其它复杂的操作留在信号处理函数之外执行;
errno
是线程安全,即每个线程有自己的errno
,但不是异步信号安全。如果信号处理函数比较复杂,且调用了可能会改变errno
值的库函数,必须考虑在信号处理函数开始时保存、结束的时候恢复被中断线程的errno
值;
- 信号处理函数只能调用可以重入的 C 库函数;譬如不能调用
malloc(),free()
以及标准 I/O 库函数等; - 信号处理函数如果需要访问全局变量,在定义此全局变量时须将其声明为
volatile,
以避免编译器不恰当的优化。
- 由于 NPTL 是 POSIX 兼容的,因此它对信号的处理是按照每进程的原则进行的;
getpid()
会为所有的线程返回相同的进程 ID。例如,如果发送了SIGSTOP
信号,那么整个进程都会停止;使用 LinuxThreads,只有接收到这个信号的线程才会停止。这样可以在基于 NPTL 的应用程序上更好地利用调试器,例如 GDB。
0 0
- 多线程,信号!!!
- 多线程信号
- c#多线程同步,信号
- 多线程信号类ManualResetEvent
- 多线程信号学习
- linux 多线程信号总结
- Linux多线程与信号
- 多线程的信号问题
- Linux多线程与信号
- 多线程中的信号总结
- linux多线程信号总结
- 多线程中的信号/槽
- linux多线程信号总结
- linux多线程信号总结
- linux多线程信号总结
- linux 多线程 信号
- Linux多线程与信号
- 多线程中的信号/槽
- 双硬盘RAID 0全攻略
- 最值得你去学习的编程语言是什么?
- AS3 图片的帧动画实现
- OpenWrt的swconfig结构框架
- android WebView总结
- 多线程,信号!!!
- HiHo 1014 Trie树
- AES128、AES256加密 在iOS上实现
- hdu 1452 Happy 2004
- xode5.1.1设置IOS欢迎界面的方法
- DB2客户端,增加查看节点和数据库编目
- 机房收费系统之无效使用Null值
- 贝叶斯后验定理与预测(信号与噪声读书笔记)
- 编程艺术五 HASH表 0-1背包