是std :: ifstream线程安全&无锁? [英] Is std::ifstream thread-safe & lock-free?
问题描述
我打算使用std :: ifstream执行从许多线程读取单个文件的打开。我的关注是如果std :: ifstream是线程安全&无锁?
更多详细信息:
- 我在Ubuntu上使用g ++ 4.4 &
- I use g++ 4.4 on Ubuntu & Windows XP, 4.0 on Leopard.
- Each thread creates its own instance of std::ifstream
$ b p>提前感谢!
请参阅 http://gcc.gnu.org/onlinedocs/libstdc++/manual/using_concurrency.html 。
在编写该手册页面时,GCC的标准库推迟了操作系统的C stdio文件缓冲。他们避免保持状态在C FILE
结构之外,并通过它实现一定程度的安全。
由于C stdio库在最后一个I / O操作周围的文件中实现单个范围的缓冲区,我没有看到无锁实现。必须对文件上的操作进行连续处理。也许无缓冲模式可以帮助;这是比我现在想做的更多的研究。
I intend to perform opening for reading a single file from many threads using std::ifstream. My concern is if std::ifstream is thread-safe & lock-free?
More details:
Thanks in advance!
See http://gcc.gnu.org/onlinedocs/libstdc++/manual/using_concurrency.html.
As of the writing of that manual page, GCC's standard library defers to the operating system's C stdio file buffering. They avoid keeping state outside the C FILE
structure and achieve some level of safety through it.
Since the C stdio library implements a buffer of a single range within the file around the last I/O operation, I don't see how a lock-free implementation is possible. The operations on a file must be processed serially. Perhaps unbuffered mode could help; that's a little more research than I'd like to do right now.
这篇关于是std :: ifstream线程安全&无锁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!