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

后端 未结 7 435
既然无缘
既然无缘 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:43

    One solution ( for both things your doing ) would be to use a gathering write via writev.

    Each thread could for example sprintf into a iovec buffer and then pass the iovec pointers to the writer thread and have it simply call writev with stdout.

    Here is an example of using writev from Advanced Unix Programming

    Under Windows you would use WSAsend for similar functionality.

    0 讨论(0)
提交回复
热议问题