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

Yan Cui

I help clients go faster for less using serverless technologies.

This article is brought to you by

Don’t reinvent the patterns. Catalyst gives you consistent APIs for messaging, data, and workflow with key microservice patterns like circuit-breakers and retries for free.

Try the Catalyst beta

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 good analogy for when either should be used:

Imagine you’ve got a single printer. Only one person can use it at a time, so if you’re got a lot of people waiting, you send them all to sleep – but you only wake one person up when the printer becomes free. This mirrors the use of Pulse.

Now imagine you run a shop. While you’re closed, customers wait outside the shop. When you open the shop, you don’t just want to wake up one customer – they can all come in now. This mirrors the use of PulseAll.

References:

StackOverflow question on the difference between Pulse and PulseAll

Whenever you’re ready, here are 3 ways I can help you:

  1. Production-Ready Serverless: Join 20+ AWS Heroes & Community Builders and 1000+ other students in levelling up your serverless game. This is your one-stop shop for quickly levelling up your serverless skills.
  2. I help clients launch product ideas, improve their development processes and upskill their teams. If you’d like to work together, then let’s get in touch.
  3. Join my community on Discord, ask questions, and join the discussion on all things AWS and Serverless.

Leave a Comment

Your email address will not be published. Required fields are marked *