Browse by Tags

Tagged Content List
  • Blog Post: ConcurrentQueue<T> holding on to a few dequeued elements

    Since .NET 4’s release, I’ve received several questions about a peculiar behavior of ConcurrentQueue<T> having to do with memory management. With Queue<T>, List<T>, and other such data structures in the .NET Framework, when you remove an element from the collection, the collection internally...
  • Blog Post: Building Async Coordination Primitives, Part 7: AsyncReaderWriterLock

    In my last past, we looked at building an AsyncLock in terms of an AsyncSemaphore . In this post, we’ll build a more advanced construct, an asynchronous reader/writer lock. An asynchronous reader/writer lock is more complicated than any of the previous coordination primitives we’ve created...
  • Blog Post: Building Async Coordination Primitives, Part 6: AsyncLock

    Last time, we looked at building an AsyncSemaphore .  Here, we’ll look at building support for an async mutual exclusion mechanism that supports scoping via ‘using’. As mentioned in the previous post, semaphores are great for throttling and resource management.  You can give a semaphore an...
  • Blog Post: Building Async Coordination Primitives, Part 5: AsyncSemaphore

    In my last few posts, I covered building an AsyncManualResetEvent , an AsyncAutoResetEvent , an AsyncCountdownEvent , and an AsyncBarrier .  In this post, I’ll cover building an AsyncSemaphore class. Semaphores have a wide range of applicability.  They’re great for throttling, for protected...
  • Blog Post: Building Async Coordination Primitives, Part 4: AsyncBarrier

    Last time, we looked at building an AsyncCountdownEvent .  At the end of the post, I highlighted a common pattern for using such a type, which is for all of the participants to signal and then wait for all of the other participants to signal as well.  This kind of synchronization is typically...
  • Blog Post: Building Async Coordination Primitives, Part 3: AsyncCountdownEvent

    In my last two posts, I discussed building AsyncManualResetEvent and AsyncAutoResetEvent coordination primitives.  In this post, I’ll build on that to create a simple AsyncCountdownEvent. A countdown event is an event that will allow waiters to complete after receiving a particular number of signals...
  • Blog Post: Building Async Coordination Primitives, Part 2: AsyncAutoResetEvent

    In my last post, I discussed building an asynchronous version of a manual-reset event .  This time, we’ll build an asynchronous version of an auto-reset event. A manual-reset event is transitioned to the signaled state when requested to do so (i.e. calling Set()), and then it remains in that state...
  • Blog Post: Building Async Coordination Primitives, Part 1: AsyncManualResetEvent

    The Task-based Async Pattern (TAP) isn’t just about asynchronous operations that you initiate and then asynchronously wait for to complete.  More generally, tasks can be used to represent all sorts of happenings, enabling you to await for any matter of condition to occur.  We can even use Tasks...
  • Blog Post: Building a custom GetOrAdd method for ConcurrentDictionary<TKey,TValue>

    I was recently asked by a developer about getting some additional information out of ConcurrentDictionary<TKey,TValue>’s GetOrAdd method.  As a reminder, GetOrAdd either returns the value for a key currently in the dictionary, or if that key doesn’t have a value, it adds a value for the key...
  • Blog Post: Await, SynchronizationContext, and Console Apps

    When I discuss the new async language features of C# and Visual Basic, one of the attributes I ascribe to the await keyword is that it “tries to bring you back to where you were.” For example, if you use await on the UI thread of your WPF application, the code that comes after the await completes...
  • Blog Post: New in .NET 4.5: ThreadLocal.Values

    Available since .NET 4, ThreadLocal<T> is a container that holds a separate value for every thread. In practice, ThreadLocal<T> is often convenient for storing per-thread counters, resources, or partial results. As mentioned earlier on this blog, we have been thinking about adding a Values...
  • Blog Post: ConcurrentDictionary Performance Improvements in .NET 4.5

    ConcurrentDictionary is a popular concurrent data structure that was introduced in .NET 4. In the .NET 4.5 release, ConcurrentDictionary gets two performance improvements. One optimization is related to the way ConcurrentDictionary avoids torn reads and writes. To explain the background, all reference...
  • Blog Post: What’s New For Parallelism in .NET 4.5

    .NET 4 and Visual Studio 2010 saw the introduction of a wide range of new support for parallelism: the Task Parallel Library (TPL), Parallel LINQ (PLINQ), new synchronization and coordination primitives and collections (e.g. ConcurrentDictionary), an improved ThreadPool for handling parallel workloads...
  • Blog Post: Parallel Merge Sort using Barrier

    Sorting is one of the most fundamental problems in software algorithms; there are many sequential sorting algorithms with different time and memory complexities, but when it comes to parallel sort, things get more complicated. I will explain a simple and scalable algorithm to write a parallel sort using...
  • Blog Post: Little-known gems: Atomic conditional removals from ConcurrentDictionary

    ConcurrentDictionary<TKey,TValue>, first introduced in .NET 4, is an efficient dictionary data structure that enables thread-safe reading and writing, meaning that multiple threads may all be accessing the dictionary at the same time without corrupting it. It supports adding through its TryAdd...
  • Blog Post: SpinWait.SpinUntil for unit testing

    One of the hidden gems in .NET 4 is the System.Threading.SpinWait type. This type is typically used for implementing lock-free solutions, and is used heavily throughout the rest of the threading and parallelism support in .NET 4. That’s why I call it “hidden”, because most folks don’t...
  • Blog Post: New Feature? :: ThreadLocal<T>.Values

    We’ve been considering adding a Values property to System.Threading.ThreadLocal<T>. Values would return a collection of all current values from all threads (e.g. what you’d get if you evaluated Value from each thread). This would allow for easy aggregations, and in fact in our Parallel...
  • Blog Post: Using Cancellation Support in .NET Framework 4

    The .NET Framework 4 introduces a new mechanism for cancellation of operations, based on new types CancellationToken and CancellationTokenSource. This cancellation mechanism is used across the parallel programming libraries: tasks, concurrent collections, and PLINQ queries. Using Cancellation Support...
  • Blog Post: Lesser-known Multi-threaded Debugging Support in Visual Studio 2010

    We’ve been very excited about the new debugging windows in Visual Studio 2010, namely Parallel Tasks and Parallel Stacks, as well as the newly revamped Threads window, and thus we’ve talked about them quite a bit. For an overview, you can read the MSDN Magazine article at http://msdn.microsoft.com/en...
  • Blog Post: ParallelExtensionsExtras Tour - #14 - SingleItemPartitioner

    (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...
  • Blog Post: ParallelExtensionsExtras Tour - #13 - AsyncCall

    (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...
  • Blog Post: Performance of Concurrent Collections in .NET 4

    .NET 4 introduces new data structures designed to simplify thread-safe access to shared data, and to increase the performance and scalability of multi-threaded applications. To best take advantage of these data structures, it helps to understand their performance characteristics in different scenarios...
  • Blog Post: ParallelExtensionsExtras Tour - #12 - AsyncCache

    (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...
  • Blog Post: ParallelExtensionsExtras Tour - #9 - ObjectPool<T>

    (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...
  • Blog Post: ParallelExtensionsExtras Tour - #8 - ReductionVariable<T>

    (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,...
Page 1 of 2 (42 items) 12