最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c - Thread-safety of closing duplicated file descriptors - Stack Overflow

programmeradmin0浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论