Ç的printf()在中断处理程序? [英] C printf() in interrupt handler?
问题描述
我用C听到的printf()是不应该在ISR中被使用。是不是因为它是一个阻塞调用,还是因为它不是重入?
I heard printf() in C is not supposed to be used in ISR. Is it because it's a blocking call, or is it because it's not re-entrant?
如果printf()函数是不可重入,那么岂不就意味着它不能用于多线程程序,除非它以某种方式同步?
If printf() is not re-entrant, then wouldn't it means that it can not be used for multi-thread program as well, unless it's 'synchronized' in some way?
谢谢,
推荐答案
我想可能是所有这些,等等。典型的的printf()
的实施可以做动态(堆)内存分配,这是一般不会在做最快的东西,也可能有问题与是非重入。色牢度的事情可以不管,因为你通常不应该花太多的时间在中断服务程序。
I think it might be all of those, and more. Typical printf()
implementations can do dynamic (heap) memory allocation, which is generally not the fastest thing to be doing, and might also have issues with being non-re-entrant. The fastness thing can matter since you're typically not supposed to spend too much time in an interrupt service routine.
请参阅this回答为约的printf()
和的malloc()
。
这篇关于Ç的printf()在中断处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!