gpt4 book ai didi

unix 管道多个编写器

转载 作者:行者123 更新时间:2023-12-04 12:24:45 25 4
gpt4 key购买 nike

如果有多个线程将固定长度的数据(比如 4 字节地址)写入单个管道,并且该管道只有一个读取器,是否可以保证读取器按顺序获取字节?换句话说,是 write()到管道原子?

最佳答案

http://pubs.opengroup.org/onlinepubs/009695399/functions/write.html

Atomic/non-atomic: A write is atomic if the whole amount written in one operation is not interleaved with data from any other process. This is useful when there are multiple writers sending data to a single reader. Applications need to know how large a write request can be expected to be performed atomically. This maximum is called {PIPE_BUF}. This volume of IEEE Std 1003.1-2001 does not say whether write requests for more than {PIPE_BUF} bytes are atomic, but requires that writes of {PIPE_BUF} or fewer bytes shall be atomic.

关于unix 管道多个编写器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4743307/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com