You are viewing a plain text version of this content. The canonical link for it is here.
Posted to proton@qpid.apache.org by serega <se...@sap.com> on 2014/01/17 16:00:34 UTC

call pn_messenger_accept from another thread

There are several discussions on this forum regarding multi-threading, and as
I understand messenger isn't thread safe.  However, my use case is simple. 
A single thread receives messages, but message processing is handed over to
another thread

Is it possible to call pn_messenger_accept(messenger, tracker, 0) from
another thread?

- Sergey



--
View this message in context: http://qpid.2158936.n2.nabble.com/call-pn-messenger-accept-from-another-thread-tp7602918.html
Sent from the Apache Qpid Proton mailing list archive at Nabble.com.

Re: call pn_messenger_accept from another thread

Posted by Bozo Dragojevic <bo...@digiverse.si>.
On 18. 01. 14 04:10, serega wrote:
> Thanks for the answer. Yes, I do have thread safe queue, so I might just
> follow your suggestion and set up a reverse queue for trackers.

If you care about latency this may not be enough because the thread 
owning the
messenger will only be able to observe the queue when it comes out of the
(most probably) pn_messenger_recv() which will happen after the next message
is received (and if this depends on previous message being accepted, 
it's deadlock not latency :).

The way out is to drive messenger in async mode and when you enqueue the 
tracker you
call pn_messenger_interrupt(), which is safe to call from another thread 
context.

Bozzo

Re: call pn_messenger_accept from another thread

Posted by serega <se...@sap.com>.
Thanks for the answer. Yes, I do have thread safe queue, so I might just
follow your suggestion and set up a reverse queue for trackers.

Sergey.



--
View this message in context: http://qpid.2158936.n2.nabble.com/call-pn-messenger-accept-from-another-thread-tp7602918p7602948.html
Sent from the Apache Qpid Proton mailing list archive at Nabble.com.

Re: call pn_messenger_accept from another thread

Posted by Rafael Schloming <rh...@alum.mit.edu>.
You would need a mutex protecting the messenger object in order to safely
call pn_messenger_accept from another thread. You can do it, but it would
likely run into complications since the messenger thread would need to hold
the mutex while blocking.

I'm guessing if you are processing messages in a different thread then you
must have some thread-safe strategy for passing message data from the
messenger thread over to the processing thread, i.e. a thread safe queue of
messages to be processed. I would think the simplest thing to do would be
to simply set up another such queue in the reverse direction to pass
trackers from the processing thread back to the messenger thread and call
pn_messenger_accept from there.

--Rafael


On Fri, Jan 17, 2014 at 10:00 AM, serega <se...@sap.com> wrote:

> There are several discussions on this forum regarding multi-threading, and
> as
> I understand messenger isn't thread safe.  However, my use case is simple.
> A single thread receives messages, but message processing is handed over to
> another thread
>
> Is it possible to call pn_messenger_accept(messenger, tracker, 0) from
> another thread?
>
> - Sergey
>
>
>
> --
> View this message in context:
> http://qpid.2158936.n2.nabble.com/call-pn-messenger-accept-from-another-thread-tp7602918.html
> Sent from the Apache Qpid Proton mailing list archive at Nabble.com.
>