comp_doc_message_queueA.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #include <boost/interprocess/detail/config_begin.hpp>
  11. //[doc_message_queueA
  12. #include <boost/interprocess/ipc/message_queue.hpp>
  13. #include <iostream>
  14. #include <vector>
  15. using namespace boost::interprocess;
  16. int main ()
  17. {
  18. try{
  19. //Erase previous message queue
  20. message_queue::remove("message_queue");
  21. //Create a message_queue.
  22. message_queue mq
  23. (create_only //only create
  24. ,"message_queue" //name
  25. ,100 //max message number
  26. ,sizeof(int) //max message size
  27. );
  28. //Send 100 numbers
  29. for(int i = 0; i < 100; ++i){
  30. mq.send(&i, sizeof(i), 0);
  31. }
  32. }
  33. catch(interprocess_exception &ex){
  34. std::cout << ex.what() << std::endl;
  35. return 1;
  36. }
  37. return 0;
  38. }
  39. //]
  40. #include <boost/interprocess/detail/config_end.hpp>