You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by "Birdsall, Dave" <da...@hp.com> on 2010/02/17 23:26:57 UTC

Interaction of pthreads and Qpid client library

Hi,

I am writing multi-threaded applications in C++ using pthreads and the Qpid client library.

What sorts of interactions does Qpid have with pthreads? Is the Qpid client library thread-safe? 

Is it possible to do all receives on one thread and sends on other threads? Any gotchas?

Thanks and regards,

Dave Birdsall
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: Interaction of pthreads and Qpid client library

Posted by Rajith Attapattu <ra...@gmail.com>.
On Wed, Feb 17, 2010 at 5:26 PM, Birdsall, Dave <da...@hp.com> wrote:
> Hi,
>
> I am writing multi-threaded applications in C++ using pthreads and the Qpid client library.
>
> What sorts of interactions does Qpid have with pthreads? Is the Qpid client library thread-safe?

> Is it possible to do all receives on one thread and sends on other threads? Any gotchas?
It's certainly possible to receive and send using different threads on
a single session.
For receiving you could create a thread and call
SubscriptionManager::run() on it.

As for gotchas I will leave it for Gordon to answer that as he's the
expert on the c++ client side.

> Thanks and regards,
>
> Dave Birdsall
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project:      http://qpid.apache.org
> Use/Interact: mailto:users-subscribe@qpid.apache.org
>
>



-- 
Regards,

Rajith Attapattu
Red Hat
http://rajith.2rlabs.com/

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: Interaction of pthreads and Qpid client library

Posted by Olivier Favre-Simon <ol...@club-internet.fr>.
On 02/18/10 14:32, Jason Schlauch wrote:
>
> On Wed, Feb 17, 2010 at 5:26 PM, Birdsall, Dave<da...@hp.com>  wrote:
>> Any gotchas?
>
> I've used boost::threads with the QPID c++ client library and the
> library appears to play nicely with threads.
>
> A typical arrangement would be to have a single connection which
> spawns multiple sessions; each thread will usually "own" a single
> session object.  A subscription manager can be used on top of the
> session to handle routing messages to your threads processing
> function.
>
> The only gotcha (at least with 0.5, possibly with later releases) is
> with the non-blocking subscriptionmanager start() method.  Don't use
> it.  You can't catch exceptions that the library generates using that
> method. Things like the "connection closed" exception will not find a
> handler and will call std::terminate on your program.  Don't design
> your program around the start() method and instead plan on using your
> own thread with the blocking run() method.
>
> I recommend using boost::thread over pthreads since the latter will
> require you to figure out how to shoehorn c++ functions into c style
> function pointers that pthreads expects.  There are certainly examples
> of how to do this on the Google, but you may as well let boost take
> care of it for you.
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project:      http://qpid.apache.org
> Use/Interact: mailto:users-subscribe@qpid.apache.org
>
>
>

Agreed.

And code you write now with boost::thread will be far easier to port to 
std::thread when new C++0x (with an hex digit now ;-) is released.


---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: Interaction of pthreads and Qpid client library

Posted by Jason Schlauch <ja...@gmail.com>.
On Wed, Feb 17, 2010 at 5:26 PM, Birdsall, Dave <da...@hp.com> wrote:
> Any gotchas?

I've used boost::threads with the QPID c++ client library and the
library appears to play nicely with threads.

A typical arrangement would be to have a single connection which
spawns multiple sessions; each thread will usually "own" a single
session object.  A subscription manager can be used on top of the
session to handle routing messages to your threads processing
function.

The only gotcha (at least with 0.5, possibly with later releases) is
with the non-blocking subscriptionmanager start() method.  Don't use
it.  You can't catch exceptions that the library generates using that
method. Things like the "connection closed" exception will not find a
handler and will call std::terminate on your program.  Don't design
your program around the start() method and instead plan on using your
own thread with the blocking run() method.

I recommend using boost::thread over pthreads since the latter will
require you to figure out how to shoehorn c++ functions into c style
function pointers that pthreads expects.  There are certainly examples
of how to do this on the Google, but you may as well let boost take
care of it for you.

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org