/* * multithread_producer.cpp * * Created on: 10 окт. 2013 г. * Author: aleksander */ #include #include #include #include boost::mutex mutex; void send(boost::interprocess::message_queue* q) { // boost::mutex::scoped_lock lock(mutex); char buff; for (int i = 0; i < 10000; i++) { q->send(&buff, 1, 0); } std::cout<<"writer thread complete"<receive(&buff, 1, size, priority); } while (size > 0); std::cout<<"reader thread complete"< threads; for (int i = 0; i < THREAD_COUNT; i++) { threads.push_back(new boost::thread(boost::bind(send, &mq))); } threads.push_back(new boost::thread(boost::bind(receive, &mq))); for (int i = 0; i < THREAD_COUNT; i++) { threads[i]->join(); } char buff; mq.send(&buff, 0, 0); threads[THREAD_COUNT]->join(); std::cout << "complete" << std::endl; } catch (std::exception &e) { std::cout << "error " << e.what() << std::endl; } return 0; }