[Boost-bugs] [Boost C++ Libraries] #9357: Request for queue::size_unsafe()

Subject: [Boost-bugs] [Boost C++ Libraries] #9357: Request for queue::size_unsafe()
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-11-08 06:27:03


#9357: Request for queue::size_unsafe()
-------------------------------------+--------------------------
 Reporter: ClaytonGDavis@… | Owner: timblechmann
     Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: lockfree
  Version: Boost Development Trunk | Severity: Cosmetic
 Keywords: |
-------------------------------------+--------------------------
 Hello,

 I have been using the lockfree queue in something like the following way
 (illustrative purposes only; please forgive any errors):


 {{{
 class MyObject;
 queue<MyObject*> Input, Output;

 void HandleObject(MyObject* obj)
 {
   // Process obj, then push it.
   ...
   assert(Output.bounded_push(obj));
 }

 // Assume Input has been filled with some number of objects.
 Output.reserve_unsafe(SizeOfInput);

 // Consume objects in multi-threaded code.
 thread_group grp;
 for(int i = 0; i < NUM_THREADS; i++) {
   grp.create_thread(bind(&queue::consume_all, &Input, &HandleObject));
 }
 grp.join_all();
 }}}

 The point is that I ensure in sequential code that the output queue has
 enough capacity to receive nodes from the input queue.

 However, there is currently no easy way to get the size of the input
 queue. The only way I've found is to pop all of its entries, count how
 many there are, and push them back into the input queue, like the rather
 ungainly (untested):
 {{{
 template<typename T>
 size_type size(queue<T> q) {
   queue<T> qtemp;
   T temp;
   size_type s = q.consume_all(bind(&queue::unsynchronized_push, &qtemp));
   qtemp.consume_all(bind(&queue::unsynchronized_push, &q));
   return s;
 }
 }}}
 Would it be possible, instead, to add member functions like
 {{{
 size_type queue::size_unsafe() const;
 size_type stack::size_unsafe() const;
 size_type spsc_queue::size_unsafe() const;
 }}}
 to simplify this sort of code? (By analogy with STL, capacity_unsafe
 might be useful to some people too, though I don't have a use-case to
 support this.)

 Thanks for this excellent addition to boost!

 Clayton Davis

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/9357>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:14 UTC