These day, I work for load resource in background thread for my project. I'm using "OGRE_THREAD_SUPPORT 2" and "OGRE_THREAD_PROVIDER 3".
Some issues I found below:
1. ResourceGroupManager::getSingleton().unloadResourceGroup is called in ResourceBackgroundQueue::handleRequest. However, resource cannot be unloaded in work thread. For unload resource group, It must be called in ResourceBackgroundQueue::handleResponse which is in main thread.
2. With ResourceGroupManager, I suggest remove OGRE_LOCK_AUTO_MUTEX with createResourceGroup, getResourceGroup and isResourceGroupInGlobalPool and add comment they are not thread safe, that means these three methods must be called in main thread. Another option is add more mutexes for different using like "add/remove ResourceGroupListener". Using only one OGRE_AUTO_MUTEX for all methods will cause deadlock and lag.
Deadlock situation generally because main thread lock ResourceGroupManager::mutex first and lock ResourceManager::mutex second, and work thread lock ResourceManager::mutex first and lock ResourceGroupManager::mutex second.
Call stack with main/work thread below.
"AB" in Main thread.
"BA" in work thread
3. For smooth with loading single resources that prepared in work thread, and then load in main thread. If smooth with loading resource group, we can initialiseResourceGroup and prepareResourceGroup in work thread, and then load resource in this resource group one by one in main thread.
I wrote my own ResourceGroupBackgroundLoader class to do this, it works fine, code attached for your reference. Review is welcome.
Minor issues with the Ogre API that can be trivial to fix
2 posts • Page 1 of 1
- Posts: 23
- Joined: Thu Jun 13, 2013 5:41 pm
There are more locking issues in Ogre's resource system when used with background threads. I don't know the ins and outs of Ogre's resource groups and resource system in general, but I figured I could get rid of the worst locking issues by releasing locks and relying on thread-safe archive implementations. See my post http://www.ogre3d.org/forums/viewtopic. ... 68#p507168 for details. (Note: duplicate thread at http://www.ogre3d.org/forums/viewtopic. ... 9&p=510821)