Unix管道多个作家 [英] unix pipe multiple writers

查看:87
本文介绍了Unix管道多个作家的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

If there are multiple threads writing fixed length data (say 4 byte address) to a single pipe and there is a single reader of that pipe, is it guaranteed that the reader will get bytes in order? In other words, is write() to a pipe atomic?

推荐答案

原子/非原子:写是原子的 如果全部写成一个 操作未与数据交错 从任何其他过程.这很有用 当有多位作家时 将数据发送到单个读取器. 应用程序需要知道一个 写请求可以预期是 原子执行.这个最大值是 称为{PIPE_BUF}.本卷IEEE Std 1003.1-2001没有说是否 撰写超过 {PIPE_BUF}个字节是原子的,但是 要求写入{PIPE_BUF}或 更少的字节应该是原子的.

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管道多个作家的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆