Linux ostream::flush上下文

Linux ostream::flush上下文,linux,multithreading,real-time,Linux,Multithreading,Real Time,我在多线程应用程序中按以下顺序使用ostream::write和ostream::flush操作: // <<-- start time measurement { ostream::write(); ostream::flush(); } //<<-- end time measurement //每个操作都锁定一个互斥锁。您的低性能几乎肯定是由于锁争用造成的。如果您将每个线程与自己的io缓冲区关联,并在程序上下文中使用fwrite_unlocked()和fflu

我在多线程应用程序中按以下顺序使用
ostream::write
ostream::flush
操作:

// <<--  start time measurement
{
ostream::write();
ostream::flush();
}
//<<--  end time measurement

//每个操作都锁定一个互斥锁。您的低性能几乎肯定是由于锁争用造成的。如果您将每个线程与自己的io缓冲区关联,并在程序上下文中使用fwrite_unlocked()和fflush_unlocked(),则可以获得更好的性能。当文件缓冲区填满时(如果文件是块缓冲的,当遇到换行符时(如果是行缓冲的),或者当调用fflush时,将完成写入(总是这样,只要缓冲区里有东西)。无论如何,我不认为你实际上在问什么很清楚。我已经编辑了这个问题