On 06/17/2013 12:42 AM, Rajesh Khan wrote:
This post is regarding the initial title of the thread. Kindly correct me
if I am wrong. I believe the objects of Qpid are not really thread safe.
This is because I tried the following code . The following method is run in
3 separate parallel threads

        void SomeClass::SomeMethod()
         {
                 connection = boost::make_shared <Connection>("127.0.0.1");
                 connection->open();
                 session  = boost::make_shared
<Session>(connection->createSession());
                 receiver = boost::make_shared
<Receiver>(session->createReceiver(address_));
                  ...
         }

I believe it is your method that is not threadsafe. The three threads are concurrently assigning to shared member variables.

What exactly do you want to happen by running that method in parallel? If you want to initialise three members (connection, session and receiver), that can't really be done in parallel in any way, it is of necessity a serial sequence of operations.

(Btw, you don't need to use make_shared or hold connections etc by pointer as the handle class you received allows for shared access).

Here connection , session and receiver are instance members of someclass
and should not have been affected if they were thread safe however this was
not the case and I would get an error when I would attempt to open a
connection. The error that I would get would be: *"No protocol received
closing"* . I resolved this problem by introducing a lock on this method.
Could anyone kindly tell me if I did the right thing here

Adding a lock makes your method threadsafe. However calling it three times is still unlikely to be the right thing.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to