Lock Free Data Structures

| No Comments

Lock free data structures are interesting I think. It’s usually much simpler to keep things simple and use regular locks but if you have a need for speed, lock free data structures can give that to you.

I was curious to know what difference it would make for a simple FIFO queue so I knocked up a mostly lock free based implementation and a conventional lock based version. I chose to make things slightly harder by choosing a fixed size queue and having it block when the queue was full.

The lock free version was nearly thirty times faster on the machine I tested it on. Disclaimer: I did this pretty quickly and I wouldn’t be surprised if there are bugs (I haven’t tested it on a multiprocessor weakly ordered architecture machine).

Here’s the code.

Leave a comment