Модель памяти Go | Participants
|
- Statistics
- Participants
- Translate into Russian
- Translation result
- 87% translated in draft. Almost done, let's finish it!
If you do not want to register an account, you can sign in with OpenID.
The Go Memory Model | ||
The Go Memory Model | ||
Introduction | ||
Happens Before | ||
Synchronization | ||
Initialization | ||
Goroutine creation | ||
Channel communication | ||
Locks | ||
Once | ||
Incorrect synchronization | ||
Introduction | ||
The Go memory model specifies the conditions under which reads of a variable in one goroutine can be guaranteed to observe values produced by writes to the same variable in a different goroutine. | Модель памяти Go определят условия, при выполнении которых, чтение значений переменных в одной гопрограмме будет гарантированно получать значения переменных, установленные записями в эту же переменную в другой гопрограмме. | |
Happens Before | ||
Within a single goroutine, reads and writes must behave as if they executed in the order specified by the program. That is, compilers and processors may reorder the reads and writes executed within a single goroutine only when the reordering does not change the behavior within that goroutine as defined by the language specification. Because of this reordering, the execution order observed by one goroutine may differ from the order perceived by another. For example, if one goroutine executes a = 1; b = 2;, another might observe the updated value of b before the updated value of a. | В рамках одной гопрограммы, чтение и запись должны иметь такой эффект, как если бы они были произведены в порядке, задаваемом программой. В том смысле, что компиляторы и процессоры могут переставлять чтения и записи, если это не изменят поведение гопрограммы в соответствие со спецификацией языка. По причине такой перестановки, порядок выполнения, наблюдаемый одной гопрограммой может отличаться от порядка, наблюдаемого другой гопрограммой. Например, если одна гопрограмма выполняет a = 1; b = 2;, другая гопрограмма может наблюдать обновленное значение b раньше обновленного значения a. | |
To specify the requirements of reads and writes, we define happens before, a partial order on the execution of memory operations in a Go program. If event e1 happens before event e2, then we say that e2 happens after e1. Also, if e1 does not happen before e2 and does not happen after e2, then we say that e1 and e2 happen concurrently. | Для определения требований к чтениям и записям, мы определяем "происходит до", частичный порядок выполнения операций с памятью в программе на Go. Если событие e1 происходит до события e2, то мы говорим, что e2 происходит после e1. Также, если е1 не происходит до e2 и не происходит после e2, то мы горим, что e1 и e2 происходят параллельно. | |
Within a single goroutine, the happens before order is the order expressed by the program. | В рамках одной гопрограммы, отношение "происходит до" определяется порядком, задаваемым программой. | |
A read r of a variable v is allowed to observe a write w to v if both of the following hold: | Чтение r переменной v может наблюдать запись w в v, если оба следующих условия выполнены: | |
1. w happens before r. | ||
2. There is no other write w' to v that happens after w but before r. | 2. Не существует другой записи w' в v, которая происходит после w, но перед r. | |
To guarantee that a read r of a variable v observes a particular write w to v, ensure that w is the only write r is allowed to observe. That is, r is guaranteed to observe w if both of the following hold: | Для того, чтобы гарантировать, что чтение r переменной v наблюдает результат определенной записи w в v, убедитесь, что w --- это единственная запись, которую может наблюдать r. Таким образом, r гарантированно наблюдает результат записи w, если выполняется следующее: | |
1. w happens before r. | ||
2. Any other write to the shared variable v either happens before w or after r. | 2. Любая другая запись в разделяемую переменную v происходит либо до w, либо после r. | |
This pair of conditions is stronger than the first pair; it requires that there are no other writes happening concurrently with w or r. | Эта пара условий сильнее первой, она требует, чтобы никакие другие записи не происходили параллельно с w или c r. |
License: Except as noted, this content is licensed under Creative Commons Attribution 3.0.

— гОперация — sim-sim