What are the most efficient and low-latency approaches for sharing data between threads in a C++ system, and why? My primary concern is minimizing latency and maximizing performance, as I have two threads that are each pinned to their own core: a thread that builds an orderbook snapshot and a thread that reads the snapshot object. I am considering using a lock-free queue with a size of just under 3 and either putting the snapshot object into the queue or passing a pointer to it. Another option mentioned to me was using a WAMP router to publish and subscribe to orderbook data and persist it in a LMDB database that is shared via memory mapping of database files. Are there any other options to consider, and what are the trade-offs and benefits of each approach in terms of latency and performance?
for those who dont have an idea regarding what an orderbook snapshot is :
class OrderbookSnapshot
{
public:
OrderbookSnapshot();
OrderbookSnapshot(std::array<Order, 10> bids, std::array<Order, 10> asks);
std::array<Order, 10> get_bids() const;
std::array<Order, 10> get_asks() const;
private:
std::array<Order, 10> bids_;
std::array<Order, 10> asks_;
};
This is what i want to share between the two threads.