Click here to Skip to main content
15,892,298 members
Articles / General Programming / Threads

A Standard Multi-threaded Dynamic Queue

Rate me:
Please Sign up or sign in to vote.
4.79/5 (24 votes)
28 Oct 2010GPL36 min read 152K   5.6K   111  
This is a standard Windows / C++ implementation of a multi-threaded queue.
================================================================================
    StandardQueues Project Overview
===============================================================================

This application demonstrates the use of some Standard "Queues" used in real time
programming techniques for inter-thread communication.

Note: the queues shown are used only in inter-thread communications, between
producers and consumers threads, but in the case of the circular buffer and
flip flop double buffer ONLY you may use the structures embedded in a shared memory
segment as to implement inter-process communication. This is not, alas, possible
with the Multi Thread Single queue as this queue is unbounded in nature and
hence not amenable to embedding in a fixed size memory segment.

The sample offers example of use of

1. class CMultiThreadSingleQueue: concurrent unbounded queue with First In
First Out (FIFO) semantics. This queue intended use is as a buffer in between
multiple producers and multiple consumers. The sample shows the use by 3
producers and 2 consumers.

2. class CCircBuffer: concurrent bounded queue with First In First Out (FIFO) 
semantics. This queue intended use is as a buffer in between a single
producer and a single consumer. Multiple consumers and producers are NOT
allowed. Messages are passed in between the two threads in FIFO order and may
be also stored in a shared segment memory for inter-process communication.

3. class CDoubleBuffer: flip flop double buffer as it may be used in between
two threads ONLY: one producer and one consumer. The double buffer is a structure
with two identical buffers that are used in a concurrent way by the two threads:
when one thread writes to a buffer the other thread may read from the second
buffer, after these operations end the buffers are swapped and the process continues.
Messages are passed in between the two threads in FIFO order and may
be also stored in a shared segment memory for inter-process communication.

/////////////////////////////////////////////////////////////////////////////

The sample application also demonstrates the techniques used in managing
threads for producers and consumers (worker threads) and for writing a 
simple multi tabbed dialog application (class CTabCtrlEx).

/////////////////////////////////////////////////////////////////////////////

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior)
Italy Italy
Senior Software Developer in C/C++ and Oracle.
Ex-physicist holding a Ph.D. on x-ray lasers.

Comments and Discussions