Re: [Boost-bugs] [Boost C++ Libraries] #8685: lockfree spsc_queue iterator pop failure

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #8685: lockfree spsc_queue iterator pop failure
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-06-11 13:58:28


#8685: lockfree spsc_queue iterator pop failure
-------------------------------+--------------------------
  Reporter: meyers@… | Owner: timblechmann
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: lockfree
   Version: Boost 1.53.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------+--------------------------

Comment (by anonymous):

 {{{
 #include <iostream>
 #include <iomanip>
 #include <algorithm>
 #include <iterator>
 #include <vector>
 #include <string>

 using namespace std;

 template <class Sequence, typename OutputIterator>
 void test_copy(const Sequence &seq, OutputIterator out)
 {
     size_t mid = seq.size() / 2;
     copy(begin(seq), begin(seq) + mid, out);
     copy(begin(seq) + mid, end(seq), out);
 }

 template <class Sequence, typename OutputIterator>
 void test_copy_fix(const Sequence &seq, OutputIterator out)
 {
     size_t mid = seq.size() / 2;
     copy(begin(seq), begin(seq) + mid, out);
     copy(begin(seq) + mid, end(seq), out + mid);
 }


 template <class Sequence>
 void print_seq(const Sequence &seq, const string& name)
 {
     cout << name << ": ";
     copy(begin(seq), end(seq), ostream_iterator<typename
 Sequence::value_type>(cout, " "));
     cout << '\n';
 }

 int main()
 {
     vector<int> source = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
     print_seq(source, "source");

     vector<int> dest1(10);
     test_copy(source, dest1.begin());
     print_seq(dest1, "dest1a");

     fill(begin(dest1), end(dest1), 0);
     test_copy_fix(source, dest1.begin());
     print_seq(dest1, "dest1b");

     dest1.clear();
     test_copy(source, back_inserter(dest1));
     print_seq(dest1, "dest1c");


     cout << "ostream: ";
     test_copy(source, ostream_iterator<int>(cout, " "));
     cout << '\n';

     // cout << "ostream_b: ";
     // test_copy_fix(source, ostream_iterator<int>(cout, " "));
     // cout << '\n';

     return 0;
 }
 }}}

 Produces this output:
 {{{
 source: 1 2 3 4 5 6 7 8 9
 dest1a: 5 6 7 8 9 0 0 0 0 0
 dest1b: 1 2 3 4 5 6 7 8 9 0
 dest1c: 1 2 3 4 5 6 7 8 9
 ostream: 1 2 3 4 5 6 7 8 9
 }}}

 The first "dest" was how I was using the spsc queue, and how I saw the
 "problem".

 If the commented out lines are enabled, the code won't compile. This
 looks like my mistake in my usage of the spsc queue and output iterators.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/8685#comment:2>
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:13 UTC