thread safe vs reentrant

来源:互联网 发布:ubuntu 安装 twisted 编辑:程序博客网 时间:2024/05/16 17:33

基本概念

通过阅读参考资料可以了解thread safe和reentrant的基本概念,并包括re-enrant 和 thread saft之间关系的举例
re-entrant but not thread saft的例子:
- https://en.wikipedia.org/wiki/Reentrancy_(computing)
- http://stackoverflow.com/questions/9116598/why-is-this-code-reentrant-but-not-thread-safe

疑问

  • 如何避免出现reentrant的问题
    – 这里给了一些建议
  • reentrant的问题,只能发生在信号处理的情况吗?
    – 答案应该是否定的,这里给出了非信号处理情况下,no-reentrant的例子

总结

  1. 对于自己编写的函数
    • 应该考虑thread safe和re-entrant的问题
  2. 对于系统函数
    • 使用时应该注意是否是re-entrant的
      – 例如strtok就是不可重入的
0 0