Skip to content

What is a busy spin? Why should you use it?

Posted in Education, and WhoCodeFirst

Busy spin is one of the technique to wait for events without releasing CPU.

It’s often done to avoid losing data in CPU cached which is lost if the thread is paused and resumed in some other core.

So, if you are working on a low latency system where your order processing thread currently doesn’t have any order, instead of sleeping or calling wait(), you can just loop and then again check the queue for new messages.

It’s only beneficial if you need to wait for a very small amount of time e.g. in microseconds or nanoseconds.

LMAX Disrupter framework, a high-performance inter-thread messaging library has a BusySpinWaitStrategy which is based on this concept and uses a busy spin loop for EventProcessors waiting on the barrier.

Happy Learning! 😇

If you enjoyed this article, Get email updates (It’s Free)
Translate »