这里4种例子都有,研究一下对不对
https://en.m.wikipedia.org/wiki/Reentrancy_(computing)
还有人给了个汉诺塔的例子:
https://stackoverflow.com/questions/9116598/why-is-this-code-reentrant-but-not-thread-safe
Reentrant but not thread-safe
The following (somewhat contrived) modification of the swap function, which is careful to leave the global data in a consistent state at the time it exits, is reentrant; however, it is not thread-safe, since there are no locks employed, it can be interrupted at any time:
int tmp;
void swap(int* x, int* y)
{
/* Save global variable. */
int s;
s = tmp;
tmp = *x;
*x = *y; /*If hardware interrupt occurs here then it will fail to keep the value of tmp. So this is also not a reentrant example*/
*y = tmp; /* Hardware interrupt might invoke isr() here. */
/* Restore global variable. */
tmp = s;
}
void isr()
{
int x = 1, y = 2;
swap(&x, &y);
}
【 在 wjhtingerx 的大作中提到: 】
: rt
--
修改:z16166 FROM 123.118.187.*
FROM 123.118.187.*