int main (int argc, char** argv) { int buff_size = BUFFER_SIZE; if (argc == 2) { buff_size = atoi (argv[1]); std::cout << "Setting buffer size to " << buff_size << " frames " << std::endl; } else { std::cout << "Using default buffer size of " << buff_size << " frames " << std::endl; } buff.setCapacity (buff_size); std::cout << "Starting the producer and consumer threads..." << std::endl; std::cout << "Press Ctrl-C to end" << std::endl; boost::thread producer (grabAndSend); boost::this_thread::sleep (boost::posix_time::seconds (2)); boost::thread consumer (receiveAndProcess); boost::thread consumer2 (receiveAndProcess); boost::thread consumer3 (receiveAndProcess); signal (SIGINT, ctrlC); producer.join (); { boost::mutex::scoped_lock io_lock (io_mutex); PCL_WARN ("Producer done\n"); } consumer.join (); consumer2.join(); consumer3.join(); PCL_WARN ("Consumers done\n"); return (0); }
void test_multi() { sc::blocking_queue<MyMovableStr> queue{}; auto take = [&](size_t count) { for (size_t i = 0; i < count; i++) { MyMovableStr el{""}; bool success = queue.take(el); slassert(success); slassert(42 == el.get_val().size()); } }; auto put = [&](size_t count) { TestStringGenerator gen{}; for (size_t i = 0; i < count; i++) { std::string str = gen.generate(42); queue.emplace(std::move(str)); } }; std::thread producer1(put, 100); std::thread producer2(put, 100); std::thread producer3(put, 100); std::thread consumer1(take, 50); std::thread consumer2(take, 50); std::thread consumer3(take, 50); std::thread consumer4(take, 50); std::thread consumer5(take, 50); std::thread consumer6(take, 50); producer1.join(); producer2.join(); producer3.join(); consumer1.join(); consumer2.join(); consumer3.join(); consumer4.join(); consumer5.join(); consumer6.join(); }