Click or drag to resize
DigitalRuneMultithreading

This section describes how to configure multithreading in DigitalRune Particles.

Multithreading in DigitalRune Particles

The ParticleSystemManager has integrated support for multithreading. Multithreading can be enabled or disabled using the property EnableMultithreading. In multithreading mode particle systems are updated in parallel on multiple threads. The property is enabled by default on systems with multiple CPU cores (most PCs and the Xbox 360). You need to disable multithreading if you decide to run all particle systems on a single thread.

The ParticleSystem has integrated support for multithreading too. Multithreading can be enabled or disabled using the property EnableMultithreading. In multithreading mode child particle systems are automatically updated in parallel on multiple threads. The property is disabled by default.

The particle effectors of a single particle system are not updated in parallel. They are updated in the order in which they were added to a particle system. (Most effects require the particle effectors to be updated in a specific sequence.)

The multithreading support is provided by the DigitalRune Base Library. The namespace DigitalRune.Threading provides a task-based threading library that works cross-platform. The solution is optimized for the .NET Compact Framework to achieve maximum performance on the Xbox 360.

The DigitalRune libraries make extensive use of the threading library. You should also take advantage of the library if you plan to implement concurrency in your application. The threading solution is fully configurable and the included task scheduler can automatically balance the workload across all available CPU cores. See class Parallel to find out more.

Caution note Caution

It is not recommended to use multiple threading solutions in one application. Using multiple independent solutions can lead to bad load balancing and oversubscription. The additional overhead can cause a performance hit.

Class Random is not thread-safe!

It is important to know that the .NET class Random, which is used by particle systems as the random number generator, is not thread-safe! Therefore, each particle system creates its own instance of Random - see also Statistics and Distributions in DigitalRune Mathematics.

If multithreading is disabled, the same random number generator can be assigned to all particle system instances (property ParticleSystemRandom) to safe a bit of memory.

See Also