同一过程中可能有多个ORB对象吗? [英] Is it possible to have several ORB objects in the same process?

查看:131
本文介绍了同一过程中可能有多个ORB对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 ORBacus .我有一个多线程应用程序,并且希望在同一过程中有几个ORB对象.这个想法是:每个线程都有自己的ORB并连接到不同服务器.

I use ORBacus. I have a multithreading application and I want to have several ORB objects in the same process. The idea is: each thread to have its own ORB and to be connected to different server.

这甚至有可能吗?如果是这样-怎么办?

Is this even possible? If so - how?

"您尝试了什么?":我有

CORBA::ORB_var m_varOrb;

在每个线程中

.每个线程调用.每个线程都有Reconnect方法,该方法执行:

in each thread. Each thread calls. Each thread has Reconnect method, which executes:

// ...
m_varOrb = CORBA::ORB_init( argc, argv );

问题,我有:

  • 当多个线程试图同时重新连接时,应用程序在m_varOrb->destroy();CORBA::ORB_init中崩溃.

我尝试同步线程,以便所有线程尝试一一(使用static mutex)重新连接到已配置的服务器-仍然无法正常工作-当一个线程试图销毁其" ORB对象时-在destroy中再次崩溃(某些断言失败,因为某些引用计数大于1;看起来像是指向实际ORB对象的引用计数指针)

I tried to sync the threads, so that all threads try to reconnect to the configured server one by one (using a static mutex) - still not working - when one thread tries to destroy "its" ORB object - crash again in destroy (some assert fails, because some reference count is > 1; looks like a reference counting pointer to the real ORB object)

我添加了条件等待,因此,仅当所有线程都已执行destroy时,线程才开始调用ORB_init.在ORB周围创建了一个 singleton 包装器类,同步了线程以相互连接,一切开始正常运行. 但这意味着-只有一个ORB,所以只有一台服务器.错误.

I added a conditional wait, so the threads start calling ORB_init only when all threads has executed destroy; made a singleton wrapper class around the ORB, sync-ed the threads to connect one after the other and everything started working perfectly fine. BUT this means - only one ORB, so only one server. Bad.

因此,所有这些使我变得很重要,我被允许每个进程仅具有一个ORB对象.我想念什么吗?

So, all of these things made me thing, that I'm allowed to have only one ORB object per process. Am I missing something?

推荐答案

默认情况下,如果在使用ORB_init()进行初始化时传递相同的"ORB id"参数,则CORBA ORB的行为应类似于单例.但是,您可能每次都传递相同的参数,这意味着ORB假定您希望所有这些线程共享相同的基础ORB实例.

By default, CORBA ORBs should behave like singletons if you pass the same "ORB id" parameter when initiatlizing them with ORB_init(). However, you're probably passing the same parameter each time, which means that the ORB assumes you want all those threads to share the same underlying ORB instance.

因此,您要做的第一件事是在ORBacus的文档中找到如何在每个线程中传递唯一的ORB ID.也许将线程ID用作判别式.

So the first thing you need to do is to find in ORBacus's documentation how to pass unique ORB IDs within each thread. Perhaps use the thread ID as the discriminant.

也就是说,您的方法可以使用改进.在每个线程中创建一个ORB是非常昂贵的操作.而是在应用程序启动时创建一个共享的ORB,然后允许每个线程对其进行访问. ORBacus应该已经保护它不能进行并发访问.确保您也只在主线上而不是在线程中进行ORB关闭/销毁.

That said, your approach could use improvement. Creating an ORB in each thread is a very expensive operation. Instead, create one shared ORB on application start and then allow each thread access to it. It should be already protected by ORBacus against concurrent access. Make sure you only do ORB shutdown/destroy in the mainline too, not in the threads.

这篇关于同一过程中可能有多个ORB对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆