Concurrency Kit Overview

The Concurrency Kit is a .NET/Mono kit that includes a port of the Task Parallel Library and extends it to support Fibers, Coroutines, and Unity. Fibers allow code paths to execute concurrently using a single thread by leveraging the co-operative yielding behavior of coroutines.

// Start task 1
var t1 = Task.Factory.StartNew(() => PatHead());
// Start task 2
var t2 = Task.Factory.StartNew(() => RubTummy());
// This task will complete when t1 and t2 complete and
// then it will continue by executing a happy dance.
Task.WhenAll(t1, t2).ContinueWith((t3) => HappyDance());

Because code written in this manner is designed with concurrency in mind, tasks can run in parallel across multiple threads or as concurrent fibers on a single thread just by changing out the task scheduler. This flexibility makes it easy to write and maintain asynchronous code that scales.

Provided Packages

The Concurrency Kit consists of four modular packages.

packages.png
Packages

Using Asynchronous Tasks

When using a .NET runtime earlier than v4, add a reference to the System.Threading.dll assembly provided by the Concurrency Kit to add support for Tasks and Thread-Safe Collections to your project.

For a full explanation of the Task programming model, please see the Task Parallel Library documentation on MSDN.

Using Fibers

Fiber support is provided by the SpicyPixel.Threading.dll assembly and it includes packages for both the core fiber features as well as an asynchronous task model for fibers.

Please see the Fibers and Fiber Tasks topics for more information.

Using Fibers in Unity

Unity specific fiber support is provided by the SpicyPixel.Threading.Unity.dll assembly and it includes a UnityFiberScheduler that can schedule work as a Unity coroutine using either the core fiber model or the task model.

The package also extends MonoBehaviour to support convenience methods for working with fibers and tasks. See Unity Integration.

Version History

Version 1.0.4

  • Integrate latest Mono version
  • AOT fixes
  • Rename scheduler 'SharedInstance' singletons to 'Default' for consistency with TPL

Version 1.0.3

  • Support iOS by working around AOT compiler limitations
  • Add the following convenience types and members:
    • class UnitySynchronizationContext
    • class UnityTaskFactory
    • class UnityTaskScheduler
    • property UnityFiberScheduler.SharedInstance
    • property ConcurrentBehaviour.SharedInstance
  • Add Unity sample ConcurrencyKitSample

Version 1.0

  • Initial release