Version: 2021.3
ジョブシステムとは何か
NativeContainer

C# Job System の安全システム

競合状態

マルチスレッドコード を書くとき、常に 競合状態 のリスクがあります。競合状態は、1 つの操作の出力が、制御外の別の処理のタイミングに依存する場合に発生します。

A race condition is not always a bug, but it is a source of nondeterministic behavior. When a race condition does cause a bug, it can be hard to find the source of the problem because it depends on timing, so you can only recreate the issue on rare occasions. Debugging it can cause the problem to disappear, because breakpoints and logging can change the timing of individual threads. Race conditions produce the most significant challenge in writing multithreaded code.

安全システム

マルチスレッドのコードを書くのを容易にするために、Unity C# Job System は競合状態の可能性があるすべての状況を検出し、それらが原因となるバグからユーザーを保護します。

For example: if the C# Job System sends a reference to data from your code in the control thread to a job, it cannot verify whether the control thread is reading the data at the same time the job is writing to it. This scenario creates a race condition.

The C# Job System solves this by sending each job a copy of the data it needs to operate on, rather than a reference to the data in the control thread. This copy isolates the data, which eliminates the race condition.

C# Job System がデータをコピーする方法は、ジョブが blittable データ型 (英語) にしかアクセスできないことを意味します。これらの型は、マネージ とネイティブコードの間でデータを渡すときに、変換の必要はありません。

C# Job System は memcpy (英語) で blittable 型をコピーし、Unity のマネージ部分とネイティブ部分の間でデータを転送することができます。ジョブのタイミングや順番を決めるときに memcpy を使用してネイティブメモリにデータを格納します。そして、ジョブを実行するときにマネージ側がそのコピーにアクセスできるようにします。詳細については、ジョブのスケジュール を参照してください。


  • 2018–06–15 公開ページ

  • C# Job System は 2018.1 で公開NewIn20181

ジョブシステムとは何か
NativeContainer
Copyright © 2020 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961