Is thread stream safe?

I am working on a program that uses several std::ifstreamto read a binary file, one std::ifstreamfor each stream. Now I need to know if it std::ofstreamis thread safe for Windows and Linux for writing to a single file. I use only one std::ofstreamand use for multiple threads.
I read different blocks using each stream and writing this block to the output file using seekp()and write(). It currently works for me, but whether this is problematic for large files.

Is the thread safe std::ofstream?

+3
source share
3 answers

++ ( /):

27.1.3 [iostreams.thread-safety]

[string.streams, file.streams], [stream.buffers] C Library [c.files] race [intro.multithread], [iostream.objects]. [: undefined [intro.multithread].

+6

- , ( std::thread , ( ++ 11 )). .

- , / , , .

+7

. .

Windows: . . msdn: ++

For Linux: In short, it is. From the document of the libstdC ++ document : "if your C platform library is thread safe, then your I / O operations will be flows at the lowest level", Is your C platform library streamable? Yes. The POSIX standard requires C stdio FILE * operations (such as fread / fwrite) to be atomic, and glibc does this.

+2
source

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


All Articles