Skip to content

Commit beb095b

Browse files
authored
Merge pull request #7 from joemphilips/poisoning
translate poisoning.md
2 parents 97563a2 + e721df5 commit beb095b

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* [Destructors](destructors.md)
3535
* [Leaking](leaking.md)
3636
* [Unwinding](unwinding.md)
37-
* [Exception Safety](exception-safety.md)
37+
* [例外安全性](exception-safety.md)
3838
* [Poisoning](poisoning.md)
3939
* [Concurrency](concurrency.md)
4040
* [Races](races.md)

src/poisoning.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,73 @@
11
# Poisoning
22

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

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

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

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

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

0 commit comments

Comments
 (0)