How to buffer stdout in memory and write it from a dedicated thread

后端 未结 7 461
既然无缘
既然无缘 2020-11-29 03:18

I have a C application with many worker threads. It is essential that these do not block so where the worker threads need to write to a file on disk, I have them write to a

7条回答
  •  粉色の甜心
    2020-11-29 03:25

    You can change how buffering works with setvbuf() or setbuf(). There's a description here: http://publications.gbdirect.co.uk/c_book/chapter9/input_and_output.html.

    [Edit]

    stdout really is a FILE*. If the existing code works with FILE*s, I don't see what prevents it from working with stdout.

提交回复
热议问题