C语言中的重入函数和递归函数有什么区别? [英] what is the difference between re-entrant function and recursive function in C?

查看:204
本文介绍了C语言中的重入函数和递归函数有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C语言中,我了解递归函数,但听说过重入函数.

那是什么?它们之间有什么区别?

In C I know about the recursive function but I heard about the re-entrant function.

What is that? And whats the difference between them?

推荐答案

如果函数支持同时执行"多个执行线程,则该函数是可重入的.这可能是由于实际的多线程,并且我在下面使用了这种情况,或者是由于其他发布者指出的其他情况.多线程是第一个想到的,也许也是最容易理解的,所以我专注于这种情况.

A function is re-entrant if it supports having multiple threads of execution "going through" it at the same time. This might be due to actual multi-threading, and I use this case below, or due to other things as pointed out by other posters. Multi-threading was the first that came to mind, and is perhaps also the easiest to understand, so I focused on that case.

这意味着该函数不能使用静态的全局"数据,因为该数据随后将被两个(或多个)并行线程访问,这通常会令人震惊.重入函数通常具有一个显式参数来保存任何特定于呼叫的状态,而不是静态地存储它.

This means that the function cannot use static "global" data, since that data would then be accessed by two (or more) threads in parallel, often breaking horribly. A re-entrant function often has an explicit argument to hold any call-specific state, rather than storing it statically.

strtok()是C标准库中函数的经典案例,众所周知,不是是可重入的.

strtok() is a classic case of a function in the C standard library that is well-known not to be re-entrant.

:评论中有很多见解,澄清和更正,因此也请阅读!谢谢大家的帮助.

: There are a bunch of insights, clarifications and corrections in the comments, so please read those as well! Thanks for the help, folks.

这篇关于C语言中的重入函数和递归函数有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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