2 / Copyright (c) 2013 Vicente J. Botet Escriba
4 / Distributed under the Boost Software License, Version 1.0. (See accompanying
5 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 [/////////////////////////////////////]
9 [section:synchronized_queues Synchronized Queues -- EXPERIMENTAL]
11 [warning These features are experimental and subject to change in future versions. There are not too much tests yet, so it is possible that you can find out some trivial bugs :(]
13 [note These features are based on the [@http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3533.html [*N3533 - C++ Concurrent Queues]] C++1y proposal from Lawrence Crowl and Chris Mysen and [@http://www.manning.com/williams/ [*C++ Concurrency in Action]] from Anthony Williams.]
16 [////////////////////]
17 [section Introduction]
19 Queues provide a mechanism for communicating data between components of a system.
21 The existing deque in the standard library is an inherently sequential data structure. Its reference-returning element access operations cannot synchronize access to those elements with other queue operations. So, concurrent pushes and pops on queues require a different interface to the queue structure.
23 Moreover, concurrency adds a new dimension for performance and semantics. Different queue implementation must trade off uncontended operation cost, contended operation cost, and element order guarantees. Some of these trade-offs will necessarily result in semantics weaker than a serial queue.
27 [/////////////////////////////////////]
28 [section:tutorial Tutorial]
30 Concurrent queues are a well know mechanism for communicating data between different threads.
32 Concurrent queues have inherently copy/move semantics for the data handling operation. Reference-returning interfaces are forbidden as multiple access to these references can not be thread-safe.
41 [/////////////////////////////////////]
42 [section:ref Reference]
44 [section:sync_queue_req Synchronized Queue Model]
46 [section:bounded_unbounded Bounded-Unbounded Queues]
48 One of the major features of a concurrent queue is whether it has a bounded-unbounded capacity.
52 [section:locking Locking/Lock-free Queues]
54 Locking queues can by nature block waiting for the queue to be non-empty or non-full.
56 Lock-free queues will have some trouble waiting for the queue to be non-empty or non-full queues. These queues can not define operations such as push (and pull for bounded queues). That is, it could have blocking operations (presumably emulated with busy wait) but not waiting operations.
59 [/////////////////////////////////////]
60 [section:closed Closed Queue]
62 Threads using a queue for communication need some mechanism to signal when the queue is no longer needed. The usual approach is add an additional out-of-band signal. However, this approach suffers from the flaw that threads waiting on either full or empty queues need to be woken up when the queue is no longer needed. Rather than require an out-of-band signal, we chose to directly support such a signal in the queue itself, which considerably simplifies coding.
64 To achieve this signal, a thread may close a queue. Once closed, no new elements may be pushed onto the queue. Push operations on a closed queue will either return queue_op_status::closed (when they have a queue_op_status return type), set the closed parameter if it has one or throw sync_queue::closed (when they do not). Elements already on the queue may be pulled off. When a queue is empty and closed, pull operations will either return queue_op_status::closed (when they have a status return), set the closed parameter if it has one or throw sync_queue::closed (when they do not).
67 [/////////////////////////////////////]
68 [section:exception Concurrent Queues Throw specification]
69 [section:locking Locking]
71 All the functions are defined as if we had in addition to its specific Throw specification the following:
74 [[Throws:] [Any exception thrown by the internal locking.]]
78 [/////////////////////////////////////]
79 [section:bad_alloc Allocation]
81 All the functions that allocate a resource are defined as if we had in addition to its specific Throw specification the following:
84 [[Throws:] [Any exception due to allocation errors.]]
89 [/////////////////////////////////////]
90 [section:BasicConcurrentQueue Basic Concurrent Queue Operations]
92 The essential solution to the problem of concurrent queuing is to shift to value-based operations, rather than reference-based operations.
94 The BasicConcurrentQueue concept models the basic operations of a concurrent queue.
96 A type `Q` meets the BasicConcurrentQueue requirements if the following expressions are well-formed and have the specified semantics
101 * `q.push_back(rve);`
102 * `q.pull_front(lre);`
103 * `lre = q.pull_front();`
104 [/* `spe = q.ptr_pull_front();`]
110 * `q` denotes a value of type `Q`,
111 * `e` denotes a value of type Q::value_type,
112 * `u` denotes a value of type Q::size_type,
113 * `lve` denotes an lvalue reference of type Q::value_type,
114 * `rve` denotes an rvalue reference of type Q::value_type:
115 [/* `spe` denotes a shared_ptr<Q::value_type>]
116 * `qs` denotes a variable of of type `queue_op_status`,
119 [/////////////////////////////////////]
120 [section:push_back `q.push_back(e);`]
124 [[Effects:] [Waits until the queue is not full (for bounded queues) and then push back `e` to the queue copying it (this could need an allocation for unbounded queues).]]
126 [[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation.]]
128 [[Postcondition:] [`! q.empty()`.]]
130 [[Return type:] [`void`.]]
132 [[Throws:] [If the queue was closed, throws sync_queue_is_closed. Any exception thrown by the copy of `e`.]]
134 [[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
139 [/////////////////////////////////////]
140 [section:push_back_m `q.push_back(rve);`]
144 [[Effects:] [Waits until the queue is not full (for bounded queues) and then push `e` to the queue moving it back in the queue (this could need an allocation for unbounded queues).]]
146 [[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation.]]
148 [[Postcondition:] [`! q.empty()`.]]
150 [[Return type:] [`void`.]]
152 [[Throws:] [If the queue is closed, throws sync_queue_is_closed. Any exception thrown by the copy of `e`.]]
154 [[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
159 [/////////////////////////////////////]
160 [section:pull_front_lv `q.pull_front(lve)`]
164 [[Effects:] [Waits until the queue is not empty and then pull_front the element from the queue `q` and moves the pulled element into `lve` (this could need an allocation for unbounded queues).]]
166 [[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation.]]
168 [[Postcondition:] [`! q.full()`.]]
170 [[Return type:] [`void`.]]
172 [[Throws:] [Any exception thrown by the move of `e`.]]
174 [[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
179 [/////////////////////////////////////]
180 [section:pull_front `e = q.pull_front()`]
184 [[Requires:] [Q::value_type is no throw move constructible. This is needed to ensure the exception safety.]]
186 [[Effects:] [Waits until the queue is not empty and not closed. If the queue is empty and closed throws sync_queue_is_closed. Otherwise pull the element from the queue `q` and moves the pulled element.]]
188 [[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation.]]
190 [[Postcondition:] [`! q.full()`.]]
192 [[Return type:] [`Q::value_type`.]]
194 [[Return:] [The pulled element.]]
196 [[Throws:] [Any exception thrown by the copy of `e`.]]
198 [[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
204 [/////////////////////////////////////]
205 [section:ptr_pull_front `spe = q.ptr_pull_front()`]
209 [/[Requires:] [Q::value_type is no throw move assignable. This is needed to ensure the exception safety. ]]
211 [[Effects:] [Waits until the queue is not empty and not closed. If the queue is empty and closed throws sync_queue_is_closed. Otherwise pull the element from the queue `q` and moves the pulled element into a shared_ptr.]]
213 [[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation.]]
215 [[Postcondition:] [`! q.full()`.]]
217 [[Return type:] [`Q::value_type`.]]
219 [[Return:] [A shared_ptr containing the pulled element.]]
221 [[Throws:] [Any exception thrown by the move of `e`. Any exception throw when allocation resources are missing. ]]
223 [[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
231 [/////////////////////////////////////]
232 [section:non_waiting Non-waiting Concurrent Queue Operations]
234 The ConcurrentQueue concept models a queue with Non-waiting operations.
237 A type `Q` meets the ConcurrentQueue requirements if is a model of a BasicConcurrentQueue and the following expressions are well-formed and have the specified semantics
239 * `s = q.try_push_back(e);`
240 * `s = q.try_push_back(rve);`
241 * `s = q.try_pull_front(lre);`
245 * `q` denotes a value of type `Q`,
246 * `e` denotes a value of type `Q::value_type`,
247 * `s` denotes a value of type `queue_status`,
248 * `u` denotes a value of type `Q::size_type`,
249 * `lve` denotes an lvalue reference of type Q::value_type,
250 * `rve` denotes an rvalue reference of type Q::value_type:
251 [/* `spe` denotes a shared_ptr<Q::value_type>]
254 [/////////////////////////////////////]
255 [section:try_push_back `s = q.try_push_back(e);`]
259 [[Effects:] [If the queue `q` is not full and not closed, push back the `e` to the queue copying it.]]
261 [[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation when the operation succeeds. ]]
263 [[Return type:] [`queue_op_status`.]]
267 - If the queue is closed, returns `queue_op_status::closed`,
269 - otherwise if the queue `q` is full return `queue_op_status::full`,
271 - otherwise return `queue_op_status::success`;
274 [[Postcondition:] [If the call returns `queue_op_status::success`, `! q.empty()`.]]
276 [[Throws:] [If the queue is closed, throws sync_queue_is_closed. Any exception thrown by the copy of `e`.]]
278 [[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
283 [/////////////////////////////////////]
284 [section:try_push_back_m `s = q.try_push_back(rve);`]
288 [[Effects:] [If the queue `q` is not full and not closed, push back the `e` onto the queue moving it.]]
290 [[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation.]]
292 [[Return type:] [`queue_op_status`.]]
296 - If the queue is closed, returns `queue_op_status::closed`,
298 - otherwise if the queue `q` is full return `queue_op_status::full`,
300 - otherwise return `queue_op_status::success`;
303 [[Postcondition:] [If the call returns `queue_op_status::success`, `! q.empty()`.]]
305 [[Throws:] [ Any exception thrown by the copy of `e`.]]
307 [[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
312 [/////////////////////////////////////]
313 [section:try_pull_front_lv `s = q.try_pull_front(lve)`]
317 [[Effects:] [If the queue is not empty pulls the element from the queue `q` and moves the pulled element into `lve` (this could need an allocation for unbounded queues).]]
319 [[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation.]]
321 [[Postcondition:] [`! q.full()`.]]
323 [[Return type:] [`bool`.]]
327 - If the queue `q` is empty return `queue_op_status::empty`,
329 - otherwise return `queue_op_status::success`;
333 [[Throws:] [Any exception thrown by the move of `e`.]]
335 [[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
341 [/////////////////////////////////////]
342 [section:non_blocking Non-blocking Concurrent Queue Operations]
344 For cases when blocking for mutual exclusion is undesirable, we have non-blocking operations.
345 The interface is the same as the try operations but is allowed to also return queue_op_status::busy
346 in case the operation is unable to complete without blocking.
348 Non-blocking operations are provided only for lock based queues
350 * `s = q.nonblocking_push_back(nb, e);`
351 * `s = q.nonblocking_push_back(nb, rve);`
352 * `s = q.nonblocking_pull_front(nb, lre);`
357 * `q` denotes a value of type `Q`,
358 * `e` denotes a value of type Q::value_type,
359 * `s` denotes a value of type `queue_status`,
360 * `lve` denotes an lvalue reference of type Q::value_type,
361 * `rve` denotes an rvalue reference of type Q::value_type:
362 [/* `spe` denotes a shared_ptr<Q::value_type>]
365 [/////////////////////////////////////]
366 [section:nonblocking_push_back `s = q.nonblocking_push_back(e);`]
370 [[Effects:] [If the queue `q` is not full and not closed, push back the `e` to the queue copying it.]]
372 [[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation when the operation succeeds. ]]
374 [[Return type:] [`queue_op_status`.]]
378 - If the operation would block, return queue_op_status::busy,
380 - otherwise, if the queue is closed, return `queue_op_status::closed`,
382 - otherwise, if the queue `q` is full return `queue_op_status::full`,
384 - otherwise return `queue_op_status::success`;]]
386 [[Postcondition:] [If the call returns `queue_op_status::success`, `! q.empty()`.]]
388 [[Throws:] [If the queue is closed, throws sync_queue_is_closed. Any exception thrown by the copy of `e`.]]
390 [[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
395 [/////////////////////////////////////]
396 [section:nonblocking_push_back_m `s = q.nonblocking_push_back(rve);`]
400 [[Effects:] [If the queue `q` is not full and not closed, push back the `e` onto the queue moving it.]]
402 [[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation.]]
404 [[Return type:] [`queue_op_status`.]]
408 - If the operation would block, return queue_op_status::busy,
410 - otherwise if the queue is closed, returns `queue_op_status::closed`,
412 - otherwise if the queue `q` is full return `queue_op_status::full`,
414 - otherwise return `queue_op_status::success`;]]
416 [[Postcondition:] [If the call returns `queue_op_status::success`, `! q.empty()`.]]
418 [[Throws:] [ Any exception thrown by the copy of `e`.]]
420 [[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
425 [/////////////////////////////////////]
426 [section:nonblocking_pull_front_lv `s = q.nonblocking_pull_front(lve)`]
430 [[Effects:] [If the queue is not empty pulls the element from the queue `q` and moves the pulled element into `lve` (this could need an allocation for unbounded queues).]]
432 [[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation.]]
434 [[Postcondition:] [`! q.full()`.]]
436 [[Return type:] [`bool`.]]
440 - If the operation would block, return queue_op_status::busy,
442 - otherwise if the queue `q` is empty return `queue_op_status::empty`,
444 - otherwise return `queue_op_status::success`;]]
446 [[Throws:] [Any exception thrown by the move of `e`.]]
448 [[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
454 [/////////////////////////////////////]
455 [section:bounded Bounded Concurrent Queue Operations]
457 Bounded queues add the following valid expressions
461 * `u = q.capacity();`
466 * `q` denotes a value of type `Q`,
467 * `b` denotes a value of type `bool`,
468 * `u` denotes a value of type `Q::size_type`,
470 [/////////////////////////////////////]
471 [section:full `b = q.full();`]
475 [[Return type:] [`bool`.]]
477 [[Return:] [Return `true` iff the queue is full.]]
479 [[Remark:] [Not all queues will have a full state, and these would always return false if the function is provided.]]
485 [/////////////////////////////////////]
486 [section:capacity `b = q.capacity();`]
490 [[Return type:] [`Q::size_type`.]]
492 [[Return:] [Return the capacity of queue.]]
499 [/////////////////////////////////////]
500 [section:closed_op Closed Concurrent Queue Operations]
502 Closed queues add the following valid expressions
507 * `s = q.wait_push_back(e);`
508 * `s = q.wait_push_back(rve);`
509 * `s = q.wait_pull_front(lre);`
511 [/////////////////////////////////////]
512 [section:wait_push_back `q.close();`]
516 [[Effects:] [Close the queue.]]
521 [/////////////////////////////////////]
522 [section:wait_push_back `b = q.closed();`]
526 [[Return type:] [`bool`.]]
528 [[Return:] [Return `true` iff the queue is closed.]]
533 [/////////////////////////////////////]
534 [section:wait_push_back `s = q.wait_push_back(e);`]
538 [[Effects:] [Waits until the queue is not full (for bounded queues) and then push back `e` to the queue copying it (this could need an allocation for unbounded queues).]]
540 [[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation.]]
542 [[Postcondition:] [`! q.empty()`.]]
544 [[Return type:] [`queue_op_status`.]]
548 - If the queue is closed return `queue_op_status::closed`,
550 - otherwise, return `queue_op_status::success` if no exception is thrown.
554 [[Throws:] [Any exception thrown by the copy of `e`.]]
556 [[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
561 [/////////////////////////////////////]
562 [section:wait_push_back_m `s = q.wait_push_back(rve);`]
566 [[Effects:] [Waits until the queue is not full (for bounded queues) and then push `e` to the queue moving it back in the queue (this could need an allocation for unbounded queues).]]
568 [[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation.]]
570 [[Postcondition:] [`! q.empty()`.]]
572 [[Return type:] [`queue_op_status`.]]
576 - If the queue is closed return `queue_op_status::closed`,
578 - otherwise, return `queue_op_status::success` if no exception is thrown.
582 [[Throws:] [Any exception thrown by the copy of `e`.]]
584 [[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
589 [/////////////////////////////////////]
590 [section:wait_pull_front_lv `s = q.wait_pull_front(lve)`]
594 [[Effects:] [if the queue is not empty and not closed, waits until the queue is not empty and then pull_front the element from the queue `q` and moves the pulled element into `lve`.]]
596 [[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation.]]
598 [[Postcondition:] [`! q.full()`.]]
600 [[Return type:] [`queue_op_status`.]]
604 - If the queue is empty and closed, return `queue_op_status::closed`,
606 - otherwise, return `queue_op_status::success` if no exception is thrown.
609 [[Throws:] [Any exception thrown by the move of `e`.]]
611 [[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
621 [/////////////////////////////////////]
622 [section:queue_op_status Queue Operation Status]
624 #include <boost/thread/concurrent_queues/queue_op_status.hpp>
628 enum class queue_op_status { success = 0, empty, full, closed, busy }
632 [/////////////////////////////////////]
633 [section:queue_base Queue Base]
635 #include <boost/thread/concurrent_queues/queue_base.hpp>
639 template <typename ValueType, class SizeType=std::size_t>
643 typedef ValueType value_type;
644 typedef SizeType size_type;
646 // Constructors/Assignment/Destructors
647 virtual ~queue_base() {};
650 virtual bool empty() const = 0;
651 virtual bool full() const = 0;
652 virtual size_type size() const = 0;
653 virtual bool closed() const = 0;
656 virtual void close() = 0;
658 virtual void push_back(const value_type& x) = 0;
659 virtual void push_back(BOOST_THREAD_RV_REF(value_type) x) = 0;
661 virtual void pull_front(value_type&) = 0;
662 virtual value_type pull_front() = 0;
664 virtual queue_op_status try_push_back(const value_type& x) = 0;
665 virtual queue_op_status try_push_back(BOOST_THREAD_RV_REF(value_type) x) = 0;
666 virtual queue_op_status try_pull_front(value_type&) = 0;
668 virtual queue_op_status nonblocking_push_back(const value_type& x) = 0;
669 virtual queue_op_status nonblocking_push_back(BOOST_THREAD_RV_REF(value_type) x) = 0;
670 virtual queue_op_status nonblocking_pull_front(value_type&) = 0;
672 virtual queue_op_status wait_push_back(const value_type& x) = 0;
673 virtual queue_op_status wait_push_back(BOOST_THREAD_RV_REF(value_type) x) = 0;
674 virtual queue_op_status wait_pull_front(value_type& elem) = 0;
680 [/////////////////////////////////////]
681 [section:queue_adaptor Queue Adaptor]
683 #include <boost/thread/concurrent_queues/queue_adaptor.hpp>
687 template <typename Queue>
688 class queue_adaptor : public queue_base<typename Queue::value_type, typename Queue::size_type>
691 typedef typename Queue::value_type value_type;
692 typedef typename Queue::size_type size_type;
694 // Constructors/Assignment/Destructors
701 size_type size() const { return queue.size(); }
707 void push_back(const value_type& x);
708 void push_back(BOOST_THREAD_RV_REF(value_type) x);
710 void pull_front(value_type& x);
711 value_type pull_front();
713 queue_op_status try_push_back(const value_type& x);
714 queue_op_status try_push_back(BOOST_THREAD_RV_REF(value_type) x);
715 queue_op_status try_pull_front(value_type& x);
717 queue_op_status nonblocking_push_back(const value_type& x);
718 queue_op_status nonblocking_push_back(BOOST_THREAD_RV_REF(value_type) x);
719 queue_op_status nonblocking_pull_front(value_type& x);
721 queue_op_status wait_push_back(const value_type& x);
722 queue_op_status wait_push_back(BOOST_THREAD_RV_REF(value_type) x);
723 queue_op_status wait_pull_front(value_type& x);
729 [/////////////////////////////////////]
730 [section:queue_views Queue Views]
732 #include <boost/thread/concurrent_queues/queue_views.hpp>
736 template <typename Queue>
737 class queue_back_view;
738 template <typename Queue>
739 class queue_front_view
742 using queue_back = queue_back_view<queue_base<T>>;
744 using queue_front = queue_front_view<queue_base<T>>;
747 [/////////////////////////////////////]
748 [section:queue_back_view Class template `queue_back_view<>`]
750 template <typename Queue>
751 class queue_back_view
754 typedef typename Queue::value_type value_type;
755 typedef typename Queue::size_type size_type;
757 // Constructors/Assignment/Destructors
758 queue_back_view(Queue& q) noexcept;
763 size_type size() const;
769 void push(const value_type& x);
770 void push(BOOST_THREAD_RV_REF(value_type) x);
772 queue_op_status try_push(const value_type& x);
773 queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x);
775 queue_op_status nonblocking_push(const value_type& x);
776 queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x);
778 queue_op_status wait_push(const value_type& x);
779 queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x);
784 [/////////////////////////////////////]
785 [section:queue_front_view Class template `queue_front_view<>`]
788 template <typename Queue>
789 class queue_front_view
792 typedef typename Queue::value_type value_type;
793 typedef typename Queue::size_type size_type;
795 // Constructors/Assignment/Destructors
796 queue_front_view(Queue& q) BOOST_NOEXCEPT;
801 size_type size() const;
807 void pull(value_type& x);
810 queue_op_status try_pull(value_type& x);
812 queue_op_status nonblocking_pull(value_type& x);
814 queue_op_status wait_pull(value_type& x);
821 [/////////////////////////////////////]
822 [section:sync_bounded_queue_ref Synchronized Bounded Queue]
824 #include <boost/thread/sync_bounded_queue.hpp>
828 struct sync_queue_is_closed : std::exception {};
830 template <typename ValueType>
831 class sync_bounded_queue;
833 // Stream-like operators
834 template <typename ValueType>
835 sync_bounded_queue<ValueType>& operator<<(sync_bounded_queue<ValueType>& sbq, ValueType&& elem);
836 template <typename ValueType>
837 sync_bounded_queue<ValueType>& operator<<(sync_bounded_queue<ValueType>& sbq, ValueType const&elem);
838 template <typename ValueType>
839 sync_bounded_queue<ValueType>& operator>>(sync_bounded_queue<ValueType>& sbq, ValueType &elem);
842 [/////////////////////////////////////]
843 [section:sync_queue_is_closed Class `sync_queue_is_closed`]
845 #include <boost/thread/sync_bounded_queue.hpp>
849 struct sync_queue_is_closed : std::exception {};
853 [/////////////////////////////////////]
854 [section:sync_bounded_queue Class template `sync_bounded_queue<>`]
856 #include <boost/thread/sync_bounded_queue.hpp>
859 template <typename ValueType>
860 class sync_bounded_queue
863 typedef ValueType value_type;
864 typedef std::size_t size_type;
866 sync_bounded_queue(sync_bounded_queue const&) = delete;
867 sync_bounded_queue& operator=(sync_bounded_queue const&) = delete;
868 explicit sync_bounded_queue(size_type max_elems);
869 template <typename Range>
870 sync_bounded_queue(size_type max_elems, Range range);
871 ~sync_bounded_queue();
876 size_type capacity() const;
877 size_type size() const;
881 void push_back(const value_type& x);
882 void push_back(value_type&& x);
884 queue_op_status try_push_back(const value_type& x);
885 queue_op_status try_push_back(value_type&&) x);
887 queue_op_status nonblocking_push_back(const value_type& x);
888 queue_op_status nonblocking_push_back(value_type&& x);
890 void pull_front(value_type&);
891 value_type pull_front();
893 queue_op_status try_pull_front(value_type&);
894 queue_op_status nonblocking_pull_front(value_type&);
901 [/ shared_ptr<ValueType> ptr_pull_front();]
903 [/////////////////////////////////////]
904 [section:constructor Constructor `sync_bounded_queue(size_type)`]
906 explicit sync_bounded_queue(size_type max_elems);
910 [[Effects:] [Constructs a sync_bounded_queue with a maximum number of elements given by `max_elems`. ]]
912 [[Throws:] [any exception that can be throw because of resources unavailable. ]]
918 [/////////////////////////////////////]
919 [section:constructort Template Constructor `sync_bounded_queue(size_type, Range)`]
921 template <typename Range>
922 sync_bounded_queue(size_type max_elems, Range range);
926 [[Effects:] [Constructs a sync_bounded_queue with a maximum number of elements given by `max_elems` and push back the elements of the range. ]]
928 [[Throws:] [any exception that can be throw because of resources unavailable. ]]
935 [/////////////////////////////////////]
936 [section:stream_out_operators Non-Member Function `operator<<()`]
938 #include <boost/thread/sync_bounded_queue.hpp>
941 template <typename ValueType>
942 sync_bounded_queue<ValueType>& operator<<(sync_bounded_queue<ValueType>& sbq, ValueType&& elem);
943 template <typename ValueType>
944 sync_bounded_queue<ValueType>& operator<<(sync_bounded_queue<ValueType>& sbq, ValueType const&elem);
948 [/////////////////////////////////////]
949 [section:stream_in_operators Non-Member Function `operator>>()`]
951 #include <boost/thread/sync_bounded_queue.hpp>
954 template <typename ValueType>
955 sync_bounded_queue<ValueType>& operator>>(sync_bounded_queue<ValueType>& sbq, ValueType &elem);
961 [/////////////////////////////////////]
962 [section:sync_queue_ref Synchronized Unbounded Queue]
964 #include <boost/thread/sync_queue.hpp>
967 template <typename ValueType>
970 // Stream-like operators
971 template <typename ValueType>
972 sync_queue<ValueType>& operator<<(sync_queue<ValueType>& sbq, ValueType&& elem);
973 template <typename ValueType>
974 sync_queue<ValueType>& operator<<(sync_queue<ValueType>& sbq, ValueType const&elem);
975 template <typename ValueType>
976 sync_queue<ValueType>& operator>>(sync_queue<ValueType>& sbq, ValueType &elem);
979 [/////////////////////////////////////]
980 [section:sync_queue Class template `sync_queue<>`]
982 #include <boost/thread/sync_queue.hpp>
986 template <typename ValueType, class Container = csbl::devector<ValueType>>
990 typedef ValueType value_type;
991 typedef Container underlying_queue_type;
992 typedef typename Container::size_type size_type;
994 sync_queue(sync_queue const&) = delete;
995 sync_queue& operator=(sync_queue const&) = delete;
997 explicit template <typename Range>
998 sync_queue(Range range); // Not yet implemented
1004 size_type size() const;
1005 bool closed() const;
1008 void push_back(const value_type& x);
1009 void push_back(value_type&& x);
1011 queue_op_status try_push_back(const value_type& x);
1012 queue_op_status try_push_back(value_type&&) x);
1014 queue_op_status nonblocking_push_back(const value_type& x);
1015 queue_op_status nonblocking_push_back(value_type&& x);
1017 void pull_front(value_type&);
1018 value_type pull_front();
1020 queue_op_status try_pull_front(value_type&);
1021 queue_op_status nonblocking_pull_front(value_type&);
1023 underlying_queue_type underlying_queue() noexcept;
1030 [/ shared_ptr<ValueType> ptr_pull_front();]
1033 [/////////////////////////////////////]
1034 [section:constructor Constructor `sync_queue(size_type)`]
1036 explicit sync_queue();
1040 [[Effects:] [Constructs an empty sync_queue. ]]
1042 [[Throws:] [any exception that can be throw because of resources unavailable. ]]
1048 [/////////////////////////////////////]
1049 [section:full Member Function `full()`]
1055 [[Returns:] [false. ]]
1060 [/////////////////////////////////////]
1061 [section:constructor Member Function `underlying_queue()`]
1063 underlying_queue_type underlying_queue() noexcept;
1067 [[Returns:] [Moves internal queue. ]]
1075 [/////////////////////////////////////]
1076 [section:stream_out_operators Non-Member Function `operator<<()`]
1078 #include <boost/thread/sync_queue.hpp>
1081 template <typename ValueType>
1082 sync_queue<ValueType>& operator<<(sync_queue<ValueType>& sbq, ValueType&& elem);
1083 template <typename ValueType>
1084 sync_queue<ValueType>& operator<<(sync_queue<ValueType>& sbq, ValueType const&elem);
1088 [/////////////////////////////////////]
1089 [section:stream_in_operators Non-Member Function `operator>>()`]
1091 #include <boost/thread/sync_queue.hpp>
1094 template <typename ValueType>
1095 sync_queue<ValueType>& operator>>(sync_queue<ValueType>& sbq, ValueType &elem);