<分区>
Possible Duplicate:
stdout thread-safe in C on Linux?
假设 thread1 和 thread2 相似,并且在它们的作业结束时它们都 printf。它是线程安全的还是他们必须以某种方式锁定 printf?
和stdout有关系吗?如果在每次 printf 之后执行 fflush(stdout) 会怎样?它会改变什么吗?
<分区>
Possible Duplicate:
stdout thread-safe in C on Linux?
假设 thread1 和 thread2 相似,并且在它们的作业结束时它们都 printf。它是线程安全的还是他们必须以某种方式锁定 printf?
和stdout有关系吗?如果在每次 printf 之后执行 fflush(stdout) 会怎样?它会改变什么吗?
最佳答案
The POSIX.1 and C-language functions that operate on character streams (represented by pointers to objects of type FILE) are required by POSIX.1c to be implemented in such a way that reentrancy is achieved (see ISO/IEC 9945:1-1996, §8.2).
注意:某些函数可以是可重入的或不可重入的,具体取决于它们的参数。
关于c - 在同时运行的线程中调用 printf 是否线程安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4353651/