Dear all,
I tried starting the Qpid Proton C++ even loop inside a thread, created
with "pthread_create()", while experimenting with the library.
However, I'm always getting a non-working code, which often causes some
weird behavior.
In particular, I tried creating an example by modifying the
"helloworld.cpp" sample code.

The modified code can be found here: https://pastebin.com/a6XLJF9k

When launching "proton::container(hw).run();" inside a normal function
(i.e. "pthread_callback(NULL)" in the code reported above), which is in
turn called from main(), everything works fine and I get the following
output:

$ ./helloworld
c1 - URL: //127.0.0.1:5672 - QUEUE NAME: examples
on_container_start
on_sendable
Hello World!

If, instead, I launch it inside a pthread callback, after creating a new
thread with "pthread_create()", the AMQP connection with the broker is
never established, and, when calling my executable multiple times, I even
get different outputs:
$ ./helloworld -> no output, no connection
$ ./helloworld
c1 - URL: 0.1:5672 - QUEUE NAME: examples -> one normal print, URL string
corrupted, no AMQP connection ("on_container_start" is never printed out)
$ ./helloworld -> no output, no connection
$ ./helloworld
c1 c1 - URL: 0.1:5672 - QUEUE NAME: examples -> URL string corrupted, "c1"
printed two times (?)
$ ./helloworld
c1 - URL: 0.1:5672 - QUEUE NAME: examples -> URL string corrupted, no AMQP
connection ("on_container_start" is never printed out)
$ ./helloworld
c1 - URL: 0.1:5672 - QUEUE NAME: examples -> URL string corrupted, no AMQP
connection ("on_container_start" is never printed out)
$ ./helloworld
c1 - URL: 0.1:5672 - QUEUE NAME: examples -> URL string corrupted, no AMQP
connection ("on_container_start" is never printed out)

I know that there are other better ways to create multithreaded Qpid Proton
clients, but do you know why I'm observing such a strange behavior, which
seem to be due to some data corruption, while there is only a single
connection to the AMQP broker (in my case, an Apache ActiveMQ 5 broker)?

Thank you very much in advance for your assistance!

Reply via email to