In this post we are concerned with Single Producer Multiple Consumers (SPMC) solutions for exchanging data in a multithreaded application. We compare performance of several locking and lock-free implementations under realistic conditions common for audio and other streaming applications.
The Problem We consider a system in which sample data are captured from one or more sensors at a regular interval. A good example is a multichannel audio card. A device driver usually invokes a user callback and passes the input samples as a parameter. The callback must finish its execution before the next block of samples becomes available, at which point it is invoked again.