reentrant & thread safe with examples

12 篇文章 0 订阅

Wiki says, In computing, a computer program or subroutine is called reentrant if multiple invocations can safely run concurrently. The concept applies even on a single processor system, where a reentrant procedure can be interrupted in the middle of its execution and then safely be called again ("re-entered") before its previous invocations complete execution.

强调两个点:1)reentrant强调的是procedure被中断,并且同一个procedure又被调用;2)强调safely run,两个方面:a. 可以运行(run),也就是不能被block(例如,一个procedure拿着锁lock被中断了,同一个procedure又被调用的时候就会因为拿不到锁lock被block,也就是不可重入);b. 所谓safely是指每次procedure调用都应该产生正确的结果。

不强调concurrently,也就是说并不强调多个调用同时运行,只强调一个procedure被中断,并且同一个procedure又被调用。concurrently是在thread safe中强调的。

Wiki says, Thread safety is a computer programming concept applicable to multi-threaded code. Thread-safe code only manipulates shared data structures in a manner that ensures that all threads behave properly and fulfill their design specifications without unintended interaction.

强调的是,1)多个thread同时运行(concurrently),2)并且结果正确。

Why are malloc() and printf() said as non-reentrant? See excellent answer in stackoverflow.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值