Reentrancy(可重入) and Thread-Safety(线程安全)

Reentrancy(可重入) and Thread-Safety(线程安全)

Throughout the documentation, the terms reentrant and thread-safe are used to mark classes and functions to indicate how they can be used in multithread applications:

线程安全

A thread-safe function can be called simultaneously from multiple threads, even when the invocations use shared data, because all references to the shared data are serialized.线程安全是指某个函数能被多线程同时调用,即使他们共享相同的数据。

可重入

A reentrant function can also be called simultaneously from multiple threads, but only if each invocation uses its own data.可重入是指某个函数能够被多线程同时调用,但是他们需要使用各自的数据。

线程安全和可重入

Hence, a thread-safe function is always reentrant, but a reentrant function is not always thread-safe.所有,线程安全的函数一定是可重入的函数,但是可重入的函数不一定是线程安全的。

扩展

By extension, a class is said to be reentrant if its member functions can be called safely from multiple threads, as long as each thread uses a different instance of the class. The class is thread-safe if its member functions can be called safely from multiple threads, even if all the threads use the same instance of the class.

举例

QPainter Class
The QPainter class performs low-level painting on widgets and other paint devices. More...

Header:
#include <QPainter> 
qmake:
QT += gui

List of all members, including inherited members
Obsolete members
Note: All functions in this class are *reentrant* . 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值