Tag: ParallelExtensionsExtras

Of late, I’ve seen multiple folks asking about how to use tasks to asynchronously execute a sequence of operations. For example, given three synchronous functions: public string DoA(string input); public string DoB(string aResult); public string DoC(string bResult); you could invoke these functions with code like: string aResult = DoA(input); string bResult = DoB(aResult); string cResult… Read more

(The full set of ParallelExtensionsExtras Tour posts is available here.) The Task Parallel Library isn’t just about CPU-bound operations. The Task class is a great representation for any asynchronous operation, even those implemented purely as asynchronous I/O. Task’s ability to represent arbitrary asynchronous operations without tying up threads is rooted in the TaskCompletionSource<TResult> class (previously… Read more

(The full set of ParallelExtensionsExtras Tour posts is available here.) The Task Parallel Library provides the Task.Wait method, which synchronously waits for the target Task to complete. If the Task completed successfully, the method simply returns. If the Task completed due to an unhandled exception or cancellation, Wait throws an appropriate exception to connote that you… Read more

(The full set of ParallelExtensionsExtras Tour posts is available here.) In a previous ParallelExtensionsExtras Tour blog post, we talked about implementing a custom partitioner for BlockingCollection<T>. Custom partitioning is an advanced but important feature supported by both Parallel.ForEach and PLINQ, as it allows the developer full control over how data is distributed during parallel processing. … Read more

(The full set of ParallelExtensionsExtras Tour posts is available here.) Producer/consumer scenarios could logically be split into two categories: those where the consumers are synchronous, blocking waiting for producers to generate data, and those where the consumers are asynchronous, such that they’re alerted to data being available and only then spin up to process the… Read more

(The full set of ParallelExtensionsExtras Tour posts is available here.) Caches are ubiquitous in computing, serving as a staple of both hardware architecture and software development. In software, caches are often implemented as dictionaries, where some data is retrieved or computed based on a key, and then that key and its resulting data/value are added… Read more

(The full set of ParallelExtensionsExtras Tour posts is available here.) Delegates in .NET may have one or more methods in their invocation list. When you invoke a delegate, such as through the Delegate.DynamicInvoke method, the net result is that all of the methods in the invocation list get invoked, one after the other. Of course, in… Read more

(The full set of ParallelExtensionsExtras Tour posts is available here.) Producer/consumer is a fundamental pattern employed in many parallel applications. With producer/consumer, one or more producer threads generate data that is consumed by one or more consumer threads. These consumers can themselves also be producers of further data, typically based on the data they were consuming,… Read more

(The full set of ParallelExtensionsExtras Tour posts is available here.) An object pool is a mechanism/pattern to avoid the repeated creation and destruction of objects. When code is done with an object, rather than allowing it to be garbage collected (and finalized if it’s finalizable), you put the object back into a special collection known as an… Read more

(The full set of ParallelExtensionsExtras Tour posts is available here.) The new .NET 4 System.Threading.ThreadLocal<T> is quite useful when you need per-thread, per-instance storage. This is in contrast to the fast ThreadStaticAttribute, which supports only per-thread storage (in .NET 4, ThreadLocal<T> actually layers on top of ThreadStaticAttribute to provide the additional per-instance behavior). ThreadLocal<T> exposes through… Read more