1//////////////////////////////////////////////////////////////////////////////
2//
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)
6//
7// See http://www.boost.org/libs/interprocess for documentation.
8//
9//////////////////////////////////////////////////////////////////////////////
10
11//[doc_message_queueA
12#include <boost/interprocess/ipc/message_queue.hpp>
13#include <iostream>
14#include <vector>
15
16using namespace boost::interprocess;
17
18int main ()
19{
20 BOOST_TRY{
21 //Erase previous message queue
22 message_queue::remove(name: "message_queue");
23
24 //Create a message_queue.
25 message_queue mq
26 (create_only //only create
27 ,"message_queue" //name
28 ,100 //max message number
29 ,sizeof(int) //max message size
30 );
31
32 //Send 100 numbers
33 for(int i = 0; i < 100; ++i){
34 mq.send(buffer: &i, buffer_size: sizeof(i), priority: 0);
35 }
36 }
37 BOOST_CATCH(interprocess_exception &ex){
38 std::cout << ex.what() << std::endl;
39 return 1;
40 } BOOST_CATCH_END
41
42 return 0;
43}
44//]
45
46

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of boost/libs/interprocess/example/comp_doc_message_queueA.cpp