Skip to content

Commit e4e0ae0

Browse files
committed
update
1 parent 8638613 commit e4e0ae0

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

1.9/ja/book/concurrency.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ shared mutable state がとてもとても悪いものであるということ
222222
ポインタの誤った使用の防止には [所有権のシステム](ownership.html) が役立ちますが、このシステムはデータ競合を排除する際にも同様に一役買います。
223223
データ競合は、並行性のバグの中で最悪なものの一つです。
224224

225-
<!-- As an example, here is a Rust program that would have a data race in many -->
225+
<!-- As an example, here is a Rust program that could have a data race in many -->
226226
<!-- languages. It will not compile: -->
227-
例として、多くの言語で起こるようなデータ競合を含んだRustプログラムをあげます
227+
例として、多くの言語で起こりうるようなデータ競合を含んだRustプログラムをあげます
228228
これは、コンパイルが通りません。
229229

230230
```ignore
@@ -254,10 +254,27 @@ fn main() {
254254
```
255255

256256
<!-- Rust knows this wouldn't be safe! If we had a reference to `data` in each -->
257-
<!-- thread, and the thread takes ownership of the reference, we'd have three -->
258-
<!-- owners! -->
257+
<!-- thread, and the thread takes ownership of the reference, we'd have three owners! -->
258+
<!-- `data` gets moved out of `main` in the first call to `spawn()`, so subsequent -->
259+
<!-- calls in the loop cannot use this variable. -->
259260
Rustはこれが安全でないだろうと知っているのです!
260261
もし、各スレッドに `data` への参照があり、スレッドごとにその参照の所有権があるとしたら、3人の所有者がいることになってしまうのです!
262+
`data` は最初の `spawn` の呼び出しで `main` からムーブしてしまっているので、ループ内の続く呼び出しはこの変数を使えないのです。
263+
264+
<!-- Note that this specific example will not cause a data race since different array -->
265+
<!-- indices are being accessed. But this can't be determined at compile time, and in -->
266+
<!-- a similar situation where `i` is a constant or is random, you would have a data -->
267+
<!-- race. -->
268+
この例では配列の異ったインデックスにアクセスしているのでデータ競合は起きません。
269+
しかしこの分離性はコンパイル時に決定出来ませんし `i` が定数や乱数だった時にデータ競合が起きます。
270+
271+
<!-- So, we need some type that lets us have more than one owning reference to a -->
272+
<!-- value. Usually, we'd use `Rc<T>` for this, which is a reference counted type -->
273+
<!-- that provides shared ownership. It has some runtime bookkeeping that keeps track -->
274+
<!-- of the number of references to it, hence the "reference count" part of its name. -->
275+
そのため、1つの値に対して2つ以上の所有権を持った参照を持てるような型が必要です。
276+
通常、この用途には `Rc<T>` を使います。これは所有権の共有を提供するリファレンスカウントの型です。
277+
実行時のなんちゃらがひつようで、リファレンスの数をカウントします。なのでリファレンスカウントです。
261278

262279
<!-- So, we need some type that lets us have more than one reference to a value and -->
263280
<!-- that we can share between threads, that is it must implement `Sync`. -->

0 commit comments

Comments
 (0)