| 1 | // Build instructions | 
|---|
| 2 | // g++ -g -I/path/to/boost/ -lpthread -lrt shm.cpp | 
|---|
| 3 | // | 
|---|
| 4 | // Before running, run the following command to ensure the system has no available shared memory: | 
|---|
| 5 | // [elemental@jsaxton-dev boost_1_5_9]$ dd if=/dev/zero of=/dev/shm/fill | 
|---|
| 6 | // dd: writing to `/dev/shm/fill': No space left on device | 
|---|
| 7 | // 16248681+0 records in | 
|---|
| 8 | // 16248680+0 records out | 
|---|
| 9 | // 8319324160 bytes (8.3 GB) copied, 10.8006 s, 770 MB/s | 
|---|
| 10 | // | 
|---|
| 11 | // This should crash with boost v1.59 with the following stack trace: | 
|---|
| 12 | // (gdb) where | 
|---|
| 13 | // #0  0x0000000000402186 in boost::interprocess::ipcdetail::atomic_cas32 (mem=0x7ffff7ee3000, with=1, cmp=0) at /home/elemental/boost_1_5_9/boost_1_59_0/boost/interprocess/detail/atomic.hpp:141 | 
|---|
| 14 | // #1  0x000000000040389c in boost::interprocess::ipcdetail::managed_open_or_create_impl<boost::interprocess::shared_memory_object, 16ul, true, false>::priv_open_or_create<boost::interprocess::ipcdetail::create_open_func<boost::interprocess::ipcdetail::basic_managed_memory_impl<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned long, 0u>, 0ul>, boost::interprocess::iset_index, 16ul> > > (this= | 
|---|
| 15 | //     0x7fffffffe0f8, type=boost::interprocess::ipcdetail::DoCreate, id=@0x7fffffffe090, size=1048576, mode=boost::interprocess::read_write, addr=0x0, perm=..., construct_func=...) | 
|---|
| 16 | //         at /home/elemental/boost_1_5_9/boost_1_59_0/boost/interprocess/detail/managed_open_or_create_impl.hpp:409 | 
|---|
| 17 | // #2  0x0000000000403163 in boost::interprocess::ipcdetail::managed_open_or_create_impl<boost::interprocess::shared_memory_object, 16ul, true, false>::managed_open_or_create_impl<boost::interprocess::ipcdetail::create_open_func<boost::interprocess::ipcdetail::basic_managed_memory_impl<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned long, 0u>, 0ul>, boost::interprocess::iset_index, 16ul> > > | 
|---|
| 18 | //     (this=0x7fffffffe0f8, id=@0x7fffffffe090, size=1048576, mode=boost::interprocess::read_write, addr=0x0, construct_func=..., perm=...) | 
|---|
| 19 | //         at /home/elemental/boost_1_5_9/boost_1_59_0/boost/interprocess/detail/managed_open_or_create_impl.hpp:184 | 
|---|
| 20 | // #3  0x0000000000402f2b in boost::interprocess::basic_managed_shared_memory<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned long, 0u>, 0ul>, boost::interprocess::iset_index>::basic_managed_shared_memory (this=0x7fffffffe0f0, name=0x4077fb "foobar", size=1048576, addr=0x0, perm=...) at /home/elemental/boost_1_5_9/boost_1_59_0/boost/interprocess/managed_shared_memory.hpp:106 | 
|---|
| 21 | // #4  0x00000000004016a2 in main (argc=1, argv=0x7fffffffe228) at shm.cpp:23 | 
|---|
| 22 | // | 
|---|
| 23 | // Note: Before running the program, run "rm /dev/shm/foobar; dd if=/dev/zero of=/dev/shm/fill2" to ensure the system has no available shared memory. | 
|---|
| 24 |  | 
|---|
| 25 | #include <iostream> | 
|---|
| 26 | #include <boost/interprocess/managed_shared_memory.hpp> | 
|---|
| 27 |  | 
|---|
| 28 | int main(int argc, char** argv) | 
|---|
| 29 | { | 
|---|
| 30 | namespace bi = boost::interprocess; | 
|---|
| 31 | bi::managed_shared_memory segment(bi::create_only, "foobar", 1 * 1024 * 1024); | 
|---|
| 32 | std::cout << "Success" << std::endl; | 
|---|
| 33 | } | 
|---|