admin管理员组

文章数量:1307121

manpage for close is clear on its multithread use for a given file descriptor. However it's not stated really clear in case of duplicated file descriptors.

If i have a file descriptor duplicated (both point to the same resource), is that thread safe to perform close of each respective fd in different threads? There is a refcount used to release a resource at the last close, but is that access thread safe?

manpage for close is clear on its multithread use for a given file descriptor. However it's not stated really clear in case of duplicated file descriptors.

If i have a file descriptor duplicated (both point to the same resource), is that thread safe to perform close of each respective fd in different threads? There is a refcount used to release a resource at the last close, but is that access thread safe?

Share Improve this question asked Feb 3 at 10:03 Viktor KhristenkoViktor Khristenko 9331 gold badge6 silver badges20 bronze badges 1
  • 1 As it says in the manpage, behavior varies across operating systems for ongoing file operations (such as write) using the same file descriptor in the same process at the time the file descriptor is being closed by the process, but other than that, you do not need to worry about it. – Ian Abbott Commented Feb 3 at 10:43
Add a comment  | 

1 Answer 1

Reset to default 2

if i have a file descriptor duplicated (both point to the same resource), is that thread safe to perform close of each respective fd in different threads?

yes

There is a refcount used to release a resource at the last close, but is that access thread safe?

yes

本文标签: cThreadsafety of closing duplicated file descriptorsStack Overflow