QPluginLoader thread safety question
-
Hi,
I have question about QPluginLoader thread safety.
For example, I have 3 objects, each have QPluginLoader instance and all 3 load the same plugin.
Each object are running on separate thread.
Is this safe? Does QPluginLoader make sure the thread safety during load and unload? -
Hi,
I have question about QPluginLoader thread safety.
For example, I have 3 objects, each have QPluginLoader instance and all 3 load the same plugin.
Each object are running on separate thread.
Is this safe? Does QPluginLoader make sure the thread safety during load and unload?@gani-cahyono Why do you want to load a plug-in more than once?
-
@gani-cahyono said in QPluginLoader thread safety question:
Does QPluginLoader make sure the thread safety during load and unload?
Rule of thumb: if the class / function does not mention that it's thread-safe then it isn't.
-
@jsulm said in QPluginLoader thread safety question:
@gani-cahyono Why do you want to load a plug-in more than once?
The objects are different classes that need to use the functions from the same plugins.
The classes doesn't each other so passing around plugins might introduce some kind of coupling. -
@jsulm said in QPluginLoader thread safety question:
@gani-cahyono Why do you want to load a plug-in more than once?
The objects are different classes that need to use the functions from the same plugins.
The classes doesn't each other so passing around plugins might introduce some kind of coupling.@gani-cahyono
I think you're either over thinking this, or you're not doing your due diligence with your dllsDo you use some kind of shared memory in your dll ?
No? than you're fine.
Yes ? Mutex the access, but keep in mind, "Dlls may be mapped in at different addresses in each process space. If so, all pointers will be incorrect." -
@gani-cahyono said in QPluginLoader thread safety question:
Does QPluginLoader make sure the thread safety during load and unload?
Rule of thumb: if the class / function does not mention that it's thread-safe then it isn't.
@J-Hilk said in QPluginLoader thread safety question:
@gani-cahyono
I think you're either over thinking this, or you're not doing your due diligence with your dllsDo you use some kind of shared memory in your dll ?
No? than you're fine.
Yes ? Mutex the access, but keep in mind, "Dlls may be mapped in at different addresses in each process space. If so, all pointers will be incorrect."Sorry, maybe I was not being clear. My question is not about the dll itself.
It's about QPluginLoader load/unload function. For example, if a QPluginLoader of plugin A in thread 1 is loading (load function hasn't return), then at the same time QPluginLoader of plugin A in thread 2 also calling load, is this safe?https://doc.qt.io/qt-5/qpluginloader.html stated
The instance() function implicitly tries to load the plugin if it has not been loaded yet. Multiple instances of QPluginLoader can be used to access the same physical plugin.
This mean, multiple QPluginLoader to the same plugin should return the same instance. But I'm not sure about thread safety the load/unload function.
@Christian-Ehrlicher said in QPluginLoader thread safety question:
Rule of thumb: if the class / function does not mention that it's thread-safe then it isn't.
I guess it is not thread safe. Thanks.
-
@gani-cahyono
Once loaded, plugins remain in memory until all instances of QPluginLoader has been unloaded, or until the application terminates. You can attempt to unload a plugin using unload(), but if other instances of QPluginLoader are using the same library, the call will fail, and unloading will only happen when every instance has called unload()
As per Qt doc