什么样的代码可以称为“重入"? [英] What kind of code can be called "re-entrant"?

查看:88
本文介绍了什么样的代码可以称为“重入"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我什么代码可以称为重入"代码吗?

Could someone tell me what code can be called "re-entrant" code?

在阅读一些实时操作系统时,我碰到了这个词.为了使代码成为可重入"代码,必须遵循哪些学科?

I came across this word when reading some real time operating system. What disciplines must be stuck to in order for code to be "re-entrant" code?

推荐答案

通常,可重入代码块是可以在较早的调用完成之前由另一个参与者输入的代码块,而不会影响第一个代码块的路径.演员本来会通过代码.也就是说,可以在代码已经运行的同时重新输入,并且仍然可以产生正确的结果.

In general, a re-entrant block of code is one that can be entered by another actor before an earlier invocation has finished, without affecting the path that the first actor would have taken through the code. That is, it is possible to re-enter the code while it's already running and still produce correct results.

在大多数情况下,角色"是同一过程的线程,但是 线程安全性 和可重入性有一点不同:并非每个线程安全块都是可重入的,但是每个可重入块都是线程安全的.也就是说,重新进入是比线程安全性更强的属性.这是 一个很好的例子 雷蒙德·陈(Raymond Chen)介绍了代码块如何是线程安全的,但又不能重入.

In most cases, the "actors" are threads of the same process, but the concepts of thread safety and re-entrant are subtly different: not every thread-safe block is re-entrant, but every re-entrant block is thread-safe. That is, re-entrancy is a stronger property than thread safety. Here's a good example from Raymond Chen of how a block of code might be thread-safe but not re-entrant.

在代码是递归的情况下有一个特例:正如Marc Gravell指出的那样,同一参与者在代码本身的调用完成之前就对其进行了调用.所有正确的递归块都是可重入的;当然,并不是每个重入块都是递归的.

There's a special case when the code is recursive: the same actor is calling into the code before its own invocation is finished, as Marc Gravell points out. All correct recursive blocks are re-entrant; of course, not every re-entrant block is recursive.

这篇关于什么样的代码可以称为“重入"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆