マルチスレッドコード を書くとき、常に 競合状態 のリスクがあります。競合状態は、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