Модель памяти Go

Google, “The Go Memory Model”, public translation into Russian from English More about this translation.

See also 3 similar translations

Translate into another language.

Participants

Kroxy362 points
fastpars347 points
eeight293 points
And others...
Join Translated.by to translate! If you already have a Translated.by account, please sign in.
If you do not want to register an account, you can sign in with OpenID.
Pages: ← previous Ctrl next next untranslated
1 2 3 4

The Go Memory Model

Модель памяти Go

History of edits (Latest: Kroxy 2 years, 6 months ago) §

The Go Memory Model

Модель памяти Go

History of edits (Latest: Kroxy 2 years, 6 months ago) §

Introduction

Введение

History of edits (Latest: Kroxy 2 years, 6 months ago) §

Happens Before

Происходит до

History of edits (Latest: Kroxy 2 years, 6 months ago) §

Synchronization

Синхронизация

History of edits (Latest: Kroxy 2 years, 6 months ago) §

Initialization

Инициализация

History of edits (Latest: Kroxy 2 years, 6 months ago) §

Goroutine creation

Создание гопрограммы (goroutine)

History of edits (Latest: eeight 2 years, 5 months ago) §

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

Channel communication

Канал связи

History of edits (Latest: Kroxy 2 years, 6 months ago) §

Locks

Блокировки

History of edits (Latest: Kroxy 2 years, 6 months ago) §

Once

Однажды

History of edits (Latest: Kroxy 2 years, 6 months ago) §

Incorrect synchronization

Неправильная синхронизация

History of edits (Latest: Kroxy 2 years, 6 months ago) §

Introduction

Введение

History of edits (Latest: Kroxy 2 years, 6 months ago) §

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 определят условия, при выполнении которых, чтение значений переменных в одной гопрограмме будет гарантированно получать значения переменных, установленные записями в эту же переменную в другой гопрограмме.

History of edits (Latest: eeight 2 years, 5 months ago) §

Happens Before

Происходит до

History of edits (Latest: eeight 2 years, 5 months ago) §

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.

History of edits (Latest: eeight 2 years, 5 months ago) §

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 происходят параллельно.

History of edits (Latest: eeight 2 years, 5 months ago) §

Within a single goroutine, the happens before order is the order expressed by the program.

В рамках одной гопрограммы, отношение "происходит до" определяется порядком, задаваемым программой.

History of edits (Latest: eeight 2 years, 5 months ago) §

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, если оба следующих условия выполнены:

History of edits (Latest: eeight 2 years, 5 months ago) §

1. w happens before r.

1. w происходит до r.

History of edits (Latest: eeight 2 years, 5 months ago) §

2. There is no other write w' to v that happens after w but before r.

2. Не существует другой записи w' в v, которая происходит после w, но перед r.

History of edits (Latest: eeight 2 years, 5 months ago) §

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, если выполняется следующее:

History of edits (Latest: eeight 2 years, 5 months ago) §

1. w happens before r.

1. w происходит до r.

History of edits (Latest: eeight 2 years, 5 months ago) §

2. Any other write to the shared variable v either happens before w or after r.

2. Любая другая запись в разделяемую переменную v происходит либо до w, либо после r.

History of edits (Latest: eeight 2 years, 5 months ago) §

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.

History of edits (Latest: eeight 2 years, 5 months ago) §
Pages: ← previous Ctrl next next untranslated
1 2 3 4

License: Except as noted, this content is licensed under Creative Commons Attribution 3.0.