gpt4 book ai didi

c - 是否有官方文档将读/写函数标记为线程安全函数?

转载 作者:太空宇宙 更新时间:2023-11-04 01:44:42 25 4
gpt4 key购买 nike

read/write 的手册页没有提到任何关于线程安全的内容

根据这个link !我知道此函数是线程安全的,但在此评论中没有指向官方文档的链接。

另一方面根据这个link !其中说:

The read() function shall attempt to read nbyte bytes
from the file associated with the open file descriptor,
fildes, into the buffer pointed to by buf.
The behavior of multiple concurrent reads on the same pipe, FIFO, or
terminal device is unspecified.

我断定读取函数不是线程安全的。

我现在很迷茫。请给我一个关于这个函数的线程安全的官方文档的链接。

我用管道测试了这个函数但是没有任何问题。(当然我知道我不能通过测试一些例子来说明任何特定的结果)

提前致谢:)

最佳答案

readwrite 的线程安全版本是preadpwrite:

pread(2)

   The pread() and pwrite() system calls are especially useful in
multithreaded applications. They allow multiple threads to perform
I/O on the same file descriptor without being affected by changes to
the file offset by other threads.

当两个线程同时 write() 时,顺序未指定(哪个写调用先完成)因此行为未指定(无同步)

关于c - 是否有官方文档将读/写函数标记为线程安全函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55957543/

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