Hi Rajesh,

On Mon, Jun 17, 2013 at 1:42 AM, Rajesh Khan <[email protected]> wrote:

>        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_));
>                  ...
>         }
>
> 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.

As Gordon already pointed out, SomeMethod() is *not* thread safe as it
is, if you're accessing it from different threads. However, if you
have an instance of SomeClass *per thread*, just for the sake of the
example, it should be okay (although still not best advice to not lock
it properly in a multi-threaded environment).

Also its not clear what your intent is here. Are you trying to
load-balance? How about you initialize your connection and session in
the constructor (or an init routine) of the class and later have a
receiver in each thread or so?

Maybe emailing the list with a small example (including main() method)
would help to clarify.

Hope this helps,
kaner

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

Reply via email to