为什么多线程时关闭标准输出缓冲区? [英] Why to turn off the standard output buffer when multithreading?

查看:131
本文介绍了为什么多线程时关闭标准输出缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学的多线程,我有一个简单的问题。

I'm trying to learn on multithreading, and I have a simple question. On most of the examples I find, the standard output buffer is turned off before letting multiple threads to use it with:

则setbuf(标准输出,NULL);

setbuf(stdout,NULL);

为什么呢? codeS打印相同的,如果我删除他们这一行!

Why? Codes print the same if I remove that line on them!

推荐答案

有可能的,他们不会打印出来的一样 - 当输出缓冲,可能无法显示马上可以改变的顺序行在线程之间输出。

It is possible that they would not print out the same - when the output is buffered it may not be displayed right away which can change the order in which the lines are output between threads.

关闭缓冲确保你知道为了语句被处决的。

Turning off buffering makes sure you know what order the statements were executed.

这篇关于为什么多线程时关闭标准输出缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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