Is std :: ifstream thread safe and unlocked?

I intend to open to read one file from many threads using std :: ifstream. I'm worried that if std :: ifstream is thread safe and not blocking?

More details:

  • I am using g ++ 4.4 on Ubuntu and Windows XP, 4.0 on Leopard.
  • Each thread creates its own instance of std :: ifstream

Thanks in advance!

+3
source share
3 answers

This implementation is defined. The C ++ standard says absolutely nothing about streaming, so any assumptions about streams inherently cause undefined or specific behavior.

, , , , , , ifstream , . , , , , , . , ifstream, , . (.. istream::good() istream::operator bool). , istream.

+2

. http://gcc.gnu.org/onlinedocs/libstdc++/manual/using_concurrency.html.

, GCC C stdio. C FILE .

C stdio -, , - . . , ; , .

+2

All std libraries are thread safe, but not asynchronous. Thus, you can call the same functions from different threads, but not on the same objects.

+1
source

Source: https://habr.com/ru/post/1676464/


All Articles