If you are not in windows or using something that is cross platform in C ++, try using Queue from the ACE libraries.
ACE_Message_Queue<ACE_MT_SYNCH> *msg_queue;
As a sample from ACE library samples, you can use To place a message in a queue:
ACE_NEW_RETURN (mb, ACE_Message_Block (rb.size (), ACE_Message_Block::MB_DATA, 0, buffer), 0); mb->msg_priority (ACE_Utils::truncate_cast<unsigned long> (rb.size ())); mb->wr_ptr (rb.size ()); ACE_DEBUG ((LM_DEBUG, "enqueueing message of size %d\n", mb->msg_priority ())); // Enqueue in priority order. if (msg_queue->enqueue_prio (mb) == -1) ACE_ERROR ((LM_ERROR, "(%t) %p\n", "put_next"));
to get from the queue:
ACE_Message_Block *mb = 0; msg_queue->dequeue_head (mb) == -1; int length = ACE_Utils::truncate_cast<int> (mb->length ()); if (length > 0) ACE_OS::puts (mb->rd_ptr ());
The advantage is that you can easily change the synchronization primitive without requiring too much code.
source share