Modelo de memória
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Índice |
[editar] Byte
You can help to correct and verify the translation. Click here for instructions.
|
(desde C++14) |
|
Predefinição:mark until c++23 |
|
Predefinição:mark since c++23 |
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[editar] Endereçamento de memória
You can help to correct and verify the translation. Click here for instructions.
- um objeto do tipo scalar (tipo aritmético, tipo ponteiro, tipo enumerado, ou std::nullptr_t)Original:an object of scalar type (arithmetic type, pointer type, enumeration type, or std::nullptr_t)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - ou a maior sequência contínua de campo de bits de tamanho diferente de zeroOriginal:or the largest contiguous sequence of bit fields of non-zero lengthThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
struct S { char a; // memory location #1 int b : 5; // memory location #2 int c : 11, // memory location #2 (continued) : 0, d : 8; // memory location #3 struct { int ee : 8; // memory location #4 } e; } obj; // The object 'obj' consists of 4 separate memory locations
[editar] Threads e condições de corrida
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
- ambas as avaliações executem na mesma thread ou no mesmo signal handler, ouOriginal:both evaluations execute on the same thread or in the same signal handler, orThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - ambas as avaliações conflitantes sejam operações atômicas (veja std::atomic), ouOriginal:both conflicting evaluations are atomic operations (see std::atomic), orThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - uma das avaliações conflitantes ocorra-antes (see std::memory_order)Original:one of the conflicting evaluations happens-before another (see std::memory_order)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
(
You can help to correct and verify the translation. Click here for instructions.
int cnt = 0; auto f = [&]{cnt++;}; std::thread t1{f}, t2{f}, t3{f}; // undefined behavior
std::atomic<int> cnt{0}; auto f = [&]{cnt++;}; std::thread t1{f}, t2{f}, t3{f}; // OK
[editar] Ordem de memória
You can help to correct and verify the translation. Click here for instructions.
[editar] Forward progress
[editar] Obstruction freedom
When only one thread that is not blocked in a standard library function executes an atomic function that is lock-free, that execution is guaranteed to complete (all standard library lock-free operations are obstruction-free)
[editar] Lock freedom
When one or more lock-free atomic functions run concurrently, at least one of them is guaranteed to complete (all standard library lock-free operations are lock-free -- it is the job of the implementation to ensure they cannot be live-locked indefinitely by other threads, such as by continuously stealing the cache line)
[editar] Progress guarantee
In a valid C++ program, every thread eventually does one of the following:
- terminate
- makes a call to an I/O library function
- performs an access through a volatile glvalue
- performs an atomic operation or a synchronization operation
No thread of execution can execute forever without performing any of these observable behaviors.
Note that it means that a program with endless recursion or endless loop (whether implemented as a for-statement or by looping goto or otherwise) has undefined behavior. This allows the compilers to remove all loops that have no observable behavior, without having to prove that they would eventually terminate.
A thread is said to make progress if it performs one of the execution steps above (I/O, volatile, atomic, or synchronization), blocks in a standard library function, or calls an atomic lock-free function that does not complete because of a non-blocked concurrent thread.
Concurrent forward progressIf a thread offers concurrent forward progress guarantee, it will make progress (as defined above) in finite amount of time, for as long as it has not terminated, regardless of whether other threads (if any) are making progress. The standard encourages, but doesn't require that the main thread and the threads started by std::thread offer concurrent forward progress guarantee. Parallel forward progressIf a thread offers parallel forward progress guarantee, the implementation is not required to ensure that the thread will eventually make progress if it has not yet executed any execution step (I/O, volatile, atomic, or synchronization), but once this thread has executed a step, it provides concurrent forward progress guarantees (this rule describes a thread in a thread pool that executes tasks in arbitrary order) Weakly parallel forward progressIf a thread offers weakly parallel forward progress guarantee, it does not guarantee to eventually make progress, regardless of whether other threads make progress or not. Such threads can still be guaranteed to make progress by blocking with forward progress guarantee delegation: if a thread P blocks in this manner on the completion of a set of threads S, then at least one thread in S will offer a forward progress guarantee that is same or stronger than P. Once that thread completes, another thread in S will be similarly strengthened. Once the set is empty, P will unblock. The parallel algorithms from the C++ standard library block with forward progress delegation on the completion of an unspecified set of library-managed threads. |
(desde C++17) |
[editar] See also
Documentação C para Memory model
|