问题描述
我发现AbstractMetaObject :: autoDelete(pObject)调用不是线程安全的,它访问一组拥有的对象。似乎从线程访问MetaObject可能会导致拥有的对象集崩溃。
这是一个问题-为什么我们不能在不赋予MeataObject所有权的情况下删除对象?
显示我们现在删除对象的方式的代码段:
// ClassLoader instance,imagine it is passed from somewhere to the working thread
Poco::ClassLoader<IProtocol> protocol_loader;
// load library,call to prevent library unload from other threads
protocol_loader.loadLibrary(plugin_lib);
// construct an object
IProtocol* proto = protocol_loader.create(protocol_class_name);
// work with the object
proto->DoGreateThings();
// give ownership to the MetaObject of object Class
// !!! autoDelete is not thread-safe but should be colled to force object destroy !!!
proto = protocol_loader.classFor(protocol_class_name).autoDelete(proto);
// do not wait library is unloaded,force object deletion
protocol_loader.destroy(protocol_class_name,proto);
// create other objects from the same lib
// ....
// unload library if not used on other threads
protocol_loader.unloadLibrary(plugin_lib);
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)