A more usable API for a mutable thread safe collection

In my last post we discussed the problems with designing a safer API for mutable thread safe collections that employ only an internal locking system.  The result was an API that was more difficult to mess up, yet pretty much unusable.  Lets take a look at this problem and see if we can come up…

17

Why are thread safe collections so hard?

Writing a collection which is mutable, thread safe and usable is an extremely difficult process.  At least that’s what you’ve likely been told all through your schooling.  But then you get out on the web and see a multitude of thread safe lists, maps and queues.  If it’s so hard, why are there so many…

52

Thread Local Storage template

Thread local storage is another method of synchronization between threads.  It is different that most synchronization cases because instead of sharing state between threads it enables developers to have independent, thread specific pieces of data which have a similar or common purpose.  The uses of thread local storage (TLS) vary greatly but is a very…

1

ActiveObject

I’ve been busy lately and neglected my series on Active Objects.  It’s been a fairly busy time for me both in and out of work.  Enough excuses, back to the fun. With the basic PipeSingleReader class, we now have the last piece necessary to create an ActiveObject.  This article will focus on building the base…

0

PipeSingleReaderNoLock

Previously we discussed a multi-thread safe queue like data structure using locks as an internal synchronization mechanism.  This time we’ll look at a version requiring no locks.  In the previous version, locks were used to synchronize access to an underlying queue which stored the data.  Removing the locks necessitates us moving away from Queue<T> to…

0

PipeSingleReader

Before we can get to building an Active Object implementation, there are some more primitive structures we need to define.  Active Objects live on a separate thread where every call is executed in a serialized fashion on that thread.  The next primitive will allow us to easily pass messages in the form of delegates from…

6

SynchronizationContext and Higher Order Functions

It’s often useful to ensure that actions occur on specific threads, in particular event handlers.  Take Windows Forms for instance where all operations on a Control must occur on the thread it was created on.  Typically this is not a problem since WinForms respond to events such as Click, Move, etc…  These events are sourced…

1

Thread Affinity

Part of creating a multithreading program is understanding which threads objects live on.  Seems simple enough and typically is.  However it’s nice to insert guarantees to match the design. One type of threading model is for objects or subsets of methods in an object to have an affinity to a particular thread.  Meaning that those…

1

Building a Future which returns no Value

In addition to Future<T> there is also the concept of Futures that don’t return any values.  Instead the perform the operation and return.  Because there is no additional data to pass between the threads building an Empty Future is fairly straight forward. The biggest decision is how to declare it.  EmptyFuture exposes no new accessible…

1

Building Future<T>

The last post dealt with building the base Future class.  Now we’ll build the child class used to run Func<TResult>’s.  The basic implementation is straight forward.  The class will run a delegate typed to Func<TResult> in the override of RunCore.  The trickiest part is how to store the value.  The value is set on one…

4