Files
cppdraft_translate/cppdraft/iostreams/threadsafety.md
2025-10-25 03:02:53 +03:00

30 lines
1.5 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[iostreams.threadsafety]
# 31 Input/output library [[input.output]](./#input.output)
## 31.2 Iostreams requirements [[iostreams.requirements]](iostreams.requirements#iostreams.threadsafety)
### 31.2.4 Thread safety [iostreams.threadsafety]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L138)
Concurrent access to a stream object ([[string.streams]](string.streams "31.8String-based streams"), [[file.streams]](file.streams "31.10File-based streams")), stream buffer
object ([[stream.buffers]](stream.buffers "31.6Stream buffers")), or C Library stream ([[c.files]](c.files "31.13C library files")) by multiple threads may result in
a data race ([[intro.multithread]](intro.multithread "6.10.2Multi-threaded executions and data races")) unless otherwise specified ([[iostream.objects]](iostream.objects "31.4Standard iostream objects"))[.](#1.sentence-1)
[*Note [1](#note-1)*:
Data races result in undefined behavior ([[intro.multithread]](intro.multithread "6.10.2Multi-threaded executions and data races"))[.](#1.sentence-2)
— *end note*]
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L146)
If one thread makes a library call *a* that writes a value to a stream
and, as a result, another thread reads this value from the stream through a
library call *b* such that this does not result in a data race, then*a*'s write synchronizes with*b*'s read[.](#2.sentence-1)