| 1 | #include <cstdlib> //std::system
|
|---|
| 2 | #include <sstream>
|
|---|
| 3 |
|
|---|
| 4 | #include <boost/interprocess/managed_shared_memory.hpp>
|
|---|
| 5 | #include <boost/lockfree/spsc_queue.hpp>
|
|---|
| 6 |
|
|---|
| 7 | using namespace boost::interprocess;
|
|---|
| 8 | typedef allocator<int, managed_shared_memory::segment_manager> ShmemAllocator;
|
|---|
| 9 | typedef boost::lockfree::spsc_queue<int, boost::lockfree::allocator<ShmemAllocator> > queue;
|
|---|
| 10 |
|
|---|
| 11 | int main (int argc, char *argv[])
|
|---|
| 12 | {
|
|---|
| 13 | struct shm_remove
|
|---|
| 14 | {
|
|---|
| 15 | shm_remove() { shared_memory_object::remove("spsc_queue_interprocess_shm"); }
|
|---|
| 16 | ~shm_remove(){ shared_memory_object::remove("spsc_queue_interprocess_shm"); }
|
|---|
| 17 | } remover;
|
|---|
| 18 |
|
|---|
| 19 | managed_shared_memory segment(create_only, "spsc_queue_interprocess_shm", 10000);
|
|---|
| 20 | ShmemAllocator alloc_inst(segment.get_segment_manager());
|
|---|
| 21 |
|
|---|
| 22 | queue* q = segment.construct<queue>("queue")(1000, alloc_inst);
|
|---|
| 23 |
|
|---|
| 24 | int i = 2;
|
|---|
| 25 | q->push(i);
|
|---|
| 26 | q->pop(i);
|
|---|
| 27 |
|
|---|
| 28 | fprintf(stdout, "i: %d\n", i);
|
|---|
| 29 |
|
|---|
| 30 | segment.destroy<queue>("queue");
|
|---|
| 31 |
|
|---|
| 32 | return 0;
|
|---|
| 33 | }
|
|---|