Threads Module User's Guide : PART II Concurrency Packages : Chapter 5 The Interthread Communication Package : The Producer‑Consumer Classes
The Producer‑Consumer Classes
The Interthread Communication package includes a family of templatized, value and pointer-based, queue and stack classes that use producer-consumer synchronization semantics to coordinate multithread read and write operations.
By default, the size of the queue and stack structures defined by these classes is limited only by available memory. The constructors for these class can accept an artificial size limit if you want to block producers when the buffer is filled.
For information on the producer-consumer classes, see the Interthread Communication page on the Modules tab of the ../sourceproref:index.htmlSourcePro C++ API Reference Guide.
For an example demonstrating the use of one of these classes, see “The RWTPCValQueue Family of Classes.”
Value and Pointer Classes
The concrete producer-consumer classes can be subdivided into groups according to their functionality. The following classes have simple producer-consumer synchronization semantics to support the exchange of data values or pointers:
RWTPCValQueue— Value-based queue
RWTPCValStack — Value-based stack
RWTPCPtrQueue — Pointer-based queue
RWTPCPtrStack — Pointer-based stack
Guarded and Prioritized Classes
The following classes have write operations that bind additional data items to each value prior to storing that value in the internal buffer. These additional data items, or decorations, vary by class and include a guard functor instance, a priority value, or both:
RWTPCValQueueGuarded — Value-based, guarded queue.
RWTPCValStackGuarded — Value-based, guarded stack.
RWTPCValQueuePrioritized — Value-based, prioritized queue.
RWTPCValStackPrioritized— Value-based, prioritized stack.
RWTPCValQueueGuardedPrioritized — Value-based, guarded, prioritized queue.
RWTPCValStackGuardedPrioritized— Value-based, guarded, prioritized stack.
The guarded classes allow a separate guard functor to be associated with each value written into the buffer. The guard functor is used during read operations to determine whether the associated value is currently eligible for retrieval from the buffer.
The prioritized classes allow a separate priority value to be associated with each value written into the buffer. The priority value is used during the write operation to determine the associated value’s insertion point within the buffer, such that the set of unread values is retrieved in priority order when read from the buffer.