1 | #include <boost/lockfree/spsc_queue.hpp>
|
---|
2 |
|
---|
3 | int main(int argc, char* argv[])
|
---|
4 | {
|
---|
5 | using namespace boost::lockfree;
|
---|
6 |
|
---|
7 | size_t capacity=8;
|
---|
8 | spsc_queue<unsigned char> q(capacity);
|
---|
9 | unsigned char data[]={45, 14, 7, 34, 2}; // 5 elements
|
---|
10 | unsigned char* dst=new unsigned char[sizeof(data)];
|
---|
11 |
|
---|
12 | // push array {45, 14, 7, 34, 2}
|
---|
13 | q.push(data, sizeof(data));
|
---|
14 |
|
---|
15 | // read data into dst buffer
|
---|
16 | // using size_t pop(OutputIterator it)
|
---|
17 | // the returned count is 5
|
---|
18 | size_t count=q.pop(dst);
|
---|
19 |
|
---|
20 | // check that data and dst are identical
|
---|
21 | // rc is 0
|
---|
22 | int rc=memcmp(data, dst, sizeof(data));
|
---|
23 |
|
---|
24 | // push array {45, 14, 7, 34, 2}
|
---|
25 | // after that operation the stored data
|
---|
26 | // consists of 2 fragments
|
---|
27 | q.push(data, sizeof(data));
|
---|
28 |
|
---|
29 | // read data into dst buffer
|
---|
30 | // using size_t pop(OutputIterator it)
|
---|
31 | // the returned count is 5
|
---|
32 |
|
---|
33 | //* ERROR:
|
---|
34 | //* If the stored data consists of 2 fragments
|
---|
35 | //* the pop(OutputIterator it) will not work properly
|
---|
36 | //* for random-access-iterator
|
---|
37 | //* the second fragmet will be written starting from
|
---|
38 | //* the same point as the first fragment:
|
---|
39 | //* See spsc_queue.hpp:224
|
---|
40 | //*
|
---|
41 | //* std::copy(internal_buffer + read_index, internal_buffer + max_size, it);
|
---|
42 | //* std::copy(internal_buffer, internal_buffer + count1, it);
|
---|
43 | //*
|
---|
44 | //* The code should be:
|
---|
45 | //* it=std::copy(internal_buffer + read_index, internal_buffer + max_size, it);
|
---|
46 | //* std::copy(internal_buffer, internal_buffer + count1, it);
|
---|
47 |
|
---|
48 |
|
---|
49 | count=q.pop(dst);
|
---|
50 |
|
---|
51 | //* ERROR
|
---|
52 | //* check that data and dst are NOT identical
|
---|
53 | //* rc is 1
|
---|
54 | rc=memcmp(data, dst, sizeof(data));
|
---|
55 |
|
---|
56 | delete[] dst;
|
---|
57 |
|
---|
58 | return 0;
|
---|
59 | }
|
---|