loudness-scanner icon indicating copy to clipboard operation
loudness-scanner copied to clipboard

set stdout/stderr to be unbuffered when they are not connected to a file

Open nu774 opened this issue 11 years ago • 2 comments

This fixes somewhat jumbled output due to mixed usage of stdout and stderr without proper calls to fflush() and letting stdio choose the default buffering strategy. On win32, pipes are often used instead pty (since there's no pty on win32), therefore this issue has higher possibility to appear. For example, running scanner in psuedo terminal application such as mintty is enough to reproduce the issue. unbuffered mode is a simple way to ensure output order to be always preserved, at the expence of tiny I/O overhead that should be negligible.

nu774 avatar Dec 16 '13 15:12 nu774

Sorry, don't merge this patch. It turned out that simply setting unbuffered mode causes problem due to multithreading. Since MSVC doesn't support line buffered mode, we cannot rely on it, too.

nu774 avatar Dec 16 '13 15:12 nu774

Hmm, sorry again. The previous comment seems my mistake (was testing with wrong branch..), it works here.

nu774 avatar Dec 16 '13 15:12 nu774