[zeromq-dev] zeromq-dev Digest, Vol 19, Issue 7
Alexander Petry
alexander.petry at itwm.fraunhofer.de
Sat Jul 11 14:43:35 CEST 2009
Hi!
> Date: Fri, 10 Jul 2009 22:10:44 +0200
> From: Ferenc Szalai <szferi at wsbricks.com>
> Subject: [zeromq-dev] inter thread shared q messaging
> To: zeromq-dev at mail.imatix.com
> Message-ID: <4A57A044.3090702 at wsbricks.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Hi
>
> I included source which try to demonstrate what I would like to achieve.
> The main idea is to broadcast message from writer thread to all reader
> thread. Unfortunatelly this is not a case with the attached source, only
> one reader thread gets the message.
>
> Is it really required to put an intermediate "broker thread" to the
> picture to resolve this issue or there is other way?
As I understood it, you should make the exchange global and each reader
binds a local queue to that exchange and receives messages through that
queue. I guess the problem with your code is, that each
reader "overwrites" the global information for the "PROCESS_Q". Just an
idea.
alex
PS: sorry for the ugly reply to the digest.
>
> #include <zmq.hpp>
> #include <boost/shared_ptr.hpp>
> #include <boost/thread.hpp>
>
> zmq::dispatcher_t *dispatcher = new zmq::dispatcher_t(3);
> zmq::locator_t *locator = new zmq::locator_t();
>
> void th_read()
> {
> zmq::api_thread_t *api = zmq::api_thread_t::create(dispatcher,
> locator);
> api->create_queue("PROCESS_Q", zmq::scope_process);
>
> zmq::message_t in_msg;
> api->receive(&in_msg);
> std::cout << (unsigned char *)in_msg.data() << std::endl;
> }
>
> void th_write()
> {
> zmq::api_thread_t *api = zmq::api_thread_t::create(dispatcher,
> locator);
> int eid = api->create_exchange("LOCAL_X");
> api->bind("LOCAL_X", "PROCESS_Q", NULL, NULL);
>
> sleep(1);
> std::string s("hello");
> zmq::message_t msg(s.size() + 1);
> memcpy(msg.data(), s.c_str(), s.size() + 1);
> api->send(eid, msg);
> }
>
> int
> main()
> {
> boost::shared_ptr<boost::thread> reader1(new boost::thread(&th_read));
> boost::shared_ptr<boost::thread> reader2(new boost::thread(&th_read));
> boost::shared_ptr<boost::thread> writer(new boost::thread(&th_write));
> reader1->join();
> reader2->join();
> writer->join();
>
> return 0;
> }
>
> --
> Regards
> Ferenc
>
>
> ------------------------------
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
> End of zeromq-dev Digest, Vol 19, Issue 7
> *****************************************
More information about the zeromq-dev
mailing list