Skip to content

Commit ea09846

Browse files
committed
translate poisoning.md
1 parent 8096b9a commit ea09846

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

src/SUMMARY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
* [Destructors](destructors.md)
3535
* [Leaking](leaking.md)
3636
* [Unwinding](unwinding.md)
37-
* [Exception Safety](exception-safety.md)
38-
* [Poisoning](poisoning.md)
37+
* [例外安全性](exception-safety.md)
38+
* [ポイズニング](poisoning.md)
3939
* [Concurrency](concurrency.md)
4040
* [Races](races.md)
4141
* [Send and Sync](send-and-sync.md)

src/poisoning.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,75 @@
1-
# Poisoning
1+
<!--# Poisoning-->
2+
#ポイズニング
23

4+
<!--
35
Although all unsafe code *must* ensure it has minimal exception safety, not all
46
types ensure *maximal* exception safety. Even if the type does, your code may
57
ascribe additional meaning to it. For instance, an integer is certainly
68
exception-safe, but has no semantics on its own. It's possible that code that
79
panics could fail to correctly update the integer, producing an inconsistent
810
program state.
11+
-->
12+
全てのunsafeな型は最低限の例外安全性を満たしていることが**必要です**が、全ての
13+
unsafeな型が**最大限**の例外安全性を満たしている必要はありません。
14+
仮に型自体が満たしていたとしても、実装が別の意味を暗黙に付与してしまう場合も
15+
あります。例えば整数型は間違いなく例外安全ですが、その(訳注: 最大限の例外安全性
16+
を担保する)セマンティクスを独自に持つわけではないため、整数をアップデートする
17+
際にpanicを起こすと、プログラムが一貫性のない状態に陥る可能性があります。
918

19+
<!--
1020
This is *usually* fine, because anything that witnesses an exception is about
1121
to get destroyed. For instance, if you send a Vec to another thread and that
1222
thread panics, it doesn't matter if the Vec is in a weird state. It will be
1323
dropped and go away forever. However some types are especially good at smuggling
1424
values across the panic boundary.
25+
-->
26+
これは**通常は**問題になることはありません。というのも例外を発見した処理は直後に
27+
死ぬためです。例えばVecを別のスレッドに送り、そのスレッドがパニックし、結果として
28+
Vecが奇妙な状態に陥ったとしても、dropされて永久に闇の彼方に葬られてしまうためです。
29+
とはいえ型によってはpanicの境界をまたいでくる場合もあります。
1530

31+
<!--
1632
These types may choose to explicitly *poison* themselves if they witness a panic.
1733
Poisoning doesn't entail anything in particular. Generally it just means
1834
preventing normal usage from proceeding. The most notable example of this is the
1935
standard library's Mutex type. A Mutex will poison itself if one of its
2036
MutexGuards (the thing it returns when a lock is obtained) is dropped during a
2137
panic. Any future attempts to lock the Mutex will return an `Err` or panic.
38+
-->
39+
こういった型は、panicに直面した際に、意図的に自分自身を**poison**する可能性があり
40+
ます。poisoningは自体は特に何か別の事態を引き起こすわけではありません。一般的に
41+
通常の手続きの継続を止めるべきであることを表しています。よく知られた例として
42+
標準ライブラリのMutex型があります。この型は対応するMutexGuards(`lock()`の返り値
43+
の型)が、panicによってdropされた際に自分自身をpoisonします。以後Mutexをlockしよう
44+
とすると`Err`を返すかpanicします。
2245

46+
<!--
2347
Mutex poisons not for true safety in the sense that Rust normally cares about. It
2448
poisons as a safety-guard against blindly using the data that comes out of a Mutex
2549
that has witnessed a panic while locked. The data in such a Mutex was likely in the
2650
middle of being modified, and as such may be in an inconsistent or incomplete state.
2751
It is important to note that one cannot violate memory safety with such a type
2852
if it is correctly written. After all, it must be minimally exception-safe!
53+
-->
54+
Mutexのpoisonは、通常の文脈で語られるRustの安全性とは異なる用途のためのものです。
55+
Mutexを扱うスレッドがlock中にパニックを引き起こした場合、Mutexの中のデータは変更中
56+
であった可能性が高く、一貫性を欠いていたり変更が未完了の状態であったりするため、
57+
そのようなデータを盲目的に扱う危険性に対する安全装置として動作します。
58+
注意しておきたいのはそのような型が適切に実装されていた場合、メモリ安全性を満たさない
59+
わけではないという点です。つまるところ、最低限の例外安全性は満たしていなくては
60+
ならないということです。
2961

62+
<!--
3063
However if the Mutex contained, say, a BinaryHeap that does not actually have the
3164
heap property, it's unlikely that any code that uses it will do
3265
what the author intended. As such, the program should not proceed normally.
3366
Still, if you're double-plus-sure that you can do *something* with the value,
3467
the Mutex exposes a method to get the lock anyway. It *is* safe, after all.
3568
Just maybe nonsense.
69+
-->
70+
しかしながら、Mutexが例えばBinaryHeapを持っていたとして、その値が実際にはヒープ
71+
として要件を満たさなかったような場合、そのデータ構造を利用するプログラムが作成者の
72+
意図通りの挙動をするということは考えにくいです。通常とは異なる振る舞いをする
73+
でしょう。とはいえ、十分に注意すればそのような場合でもその値が**何かに**使える
74+
可能性はあります。safe**では**あるのです。ただ、それはナンセンスであるということと
75+
は矛盾しないのです。

0 commit comments

Comments
 (0)