Threading

Be Lazy, but be ware of initialization exception

.Net 4 introduced the Lazy<T> type which allows you to create an object that can be lazily initialized so that you can delay the creation of large objects, for instance. However, if your initialization logic has the potential to except at runtime (e.g. time out exceptions reading from some external data source) then you should …

Be Lazy, but be ware of initialization exception Read More »

Takeaways from Gael Fraiteur’s multithreading talk

After watching Gael’s recent SkillsMatter talk on multithreading I’ve put together some notes from a very educational talk:   Hardware Cache Hierarchy Four levels of cache L1 (per core) – typically used for instructions L2 (per core) L3 (per die) DRAM (all processors) Data can be cached in multiple caches, and synchronization happens through an …

Takeaways from Gael Fraiteur’s multithreading talk Read More »

SmartThreadPool – What happens when you take on more than you can chew

I’ve covered the topic of using SmartThreadPool and the framework thread pool in more details here and here, this post will instead focus on a more specific scenario where the rate of new work items being queued outstrips the pool’s ability to process those items and what happens then. First, let’s try to quantify the …

SmartThreadPool – What happens when you take on more than you can chew Read More »

.Net Threading – BeginInvoke uses the thread pool

For a while now I’ve been curious as to whether the CLR uses the ThreadPool to execute a delegate when BeginInvoke is called: Whilst common sense dictates that this must surely be true, I couldn’t be certain since I haven’t managed to find any confirmation in the documentations. Thanks to Jon Skeet and Jeff Sternal …

.Net Threading – BeginInvoke uses the thread pool Read More »

Threading – introducing SmartThreadPool

As I’ve mentioned in my previous post, the biggest problem with using the .Net ThreadPool is that there’s a limited number of threads in the pool and you’ll be sharing with other .Net framework classes so you need to be on your best behaviour and not hog the thread pool with long running or blocking …

Threading – introducing SmartThreadPool Read More »

Threading – using the ThreadPool vs. creating your own threads

There are a lot of discussions on the pros and cons of using the ThreadPool and creating your own threads. Having spent a bit of time reading what others have to say, here’s a summary of the things I’ve picked up on. The problem with creating your own threads Creating and destroying threads has a …

Threading – using the ThreadPool vs. creating your own threads Read More »

Threading – Producer-Consumer Pattern

Having run into a bit of deadlocking issue while working on Bingo.Net I spent a bit of time reading into the Producer-Consumer pattern and here’s what I learnt which I hope you’ll find useful too. AutoResetEvent and ManualResetEvent To start off, MSDN has an introductory article on how to synchronize a producer and a consumer …

Threading – Producer-Consumer Pattern Read More »

Threading – when to use Monitor.Pulse and Monitor.PulseAll

Ever wondered when you should use Monitor.Pulse and when you should use Monitor.PulseAll given that only one thread will be able to acquire the lock even if you wake up multiple threads? I did, and that’s when I stumbled across a similar question on StackOverflow and as ever, Jon Skeet came up with a really …

Threading – when to use Monitor.Pulse and Monitor.PulseAll Read More »

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close