]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/interprocess/example/comp_doc_anonymous_conditionB.cpp
1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2006-2012. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 //////////////////////////////////////////////////////////////////////////////
10 #include <boost/interprocess/detail/config_begin.hpp>
11 //[doc_anonymous_conditionB
12 #include <boost/interprocess/shared_memory_object.hpp>
13 #include <boost/interprocess/mapped_region.hpp>
14 #include <boost/interprocess/sync/scoped_lock.hpp>
17 #include "doc_anonymous_condition_shared_data.hpp"
19 using namespace boost::interprocess
;
23 //Create a shared memory object.
24 shared_memory_object shm
25 (open_only
//only create
26 ,"MySharedMemory" //name
27 ,read_write
//read-write mode
31 //Map the whole shared memory in this process
34 ,read_write
//Map it as read-write
37 //Get the address of the mapped region
38 void * addr
= region
.get_address();
40 //Obtain a pointer to the shared structure
41 trace_queue
* data
= static_cast<trace_queue
*>(addr
);
43 //Print messages until the other process marks the end
44 bool end_loop
= false;
46 scoped_lock
<interprocess_mutex
> lock(data
->mutex
);
47 if(!data
->message_in
){
48 data
->cond_empty
.wait(lock
);
50 if(std::strcmp(data
->items
, "last message") == 0){
55 std::cout
<< data
->items
<< std::endl
;
56 //Notify the other process that the buffer is empty
57 data
->message_in
= false;
58 data
->cond_full
.notify_one();
63 catch(interprocess_exception
&ex
){
64 std::cout
<< ex
.what() << std::endl
;
71 #include <boost/interprocess/detail/config_end.hpp>