www.jpct.net

jPCT-AE - a 3d engine for Android => Bugs => Topic started by: Thomas. on January 26, 2013, 04:23:30 pm

Title: Loader - thread safe
Post by: Thomas. on January 26, 2013, 04:23:30 pm
Is Loader thread safe? I tried to load objects in many threads for more speed, but something is wrong...

My test case
http://dl.dropbox.com/u/26148874/TestProject.rar (http://dl.dropbox.com/u/26148874/TestProject.rar)
Title: Re: Loader - thread safe
Post by: EgonOlsen on January 26, 2013, 08:21:29 pm
Loader should be thread safe. But your threading code is strange. You aren't doing any multi-threading in it (because you are calling run() instead of start()) and if you were, you aren't waiting for the loaders to finish. Have you tried something like

Code: [Select]
List<MyLoader> loaders=new ArrayList<MyLoader>();
for (int i = 0; i < cpus; i++) {
MyLoader loader = new MyLoader();
loaders.add(loader);
loader.start();
}

for (MyLoader loader:loaders) {
try {
loader.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

instead?
Title: Re: Loader - thread safe
Post by: Thomas. on January 26, 2013, 09:18:45 pm
Oh sorry, I looked at the code and I found one more bug :-[ It seems compile is done when object is rendered, is possible to do it when is called method Object3D.compile() or maybe Object3D.compile(FrameBuffer)? GPU can be control by one thread, so maybe it not possible...
Title: Re: Loader - thread safe
Post by: EgonOlsen on January 26, 2013, 09:43:17 pm
No, not possible. It has to happen in the thread that is associated with the gl context.
Title: Re: Loader - thread safe
Post by: Thomas. on January 30, 2013, 12:36:58 am
I got this message when I was loading objects

Code: [Select]
01-30 00:27:54.383: W/System.err(929): java.util.ConcurrentModificationException
01-30 00:27:54.383: W/System.err(929): at java.util.HashMap$HashIterator.nextEntry(HashMap.java:792)
01-30 00:27:54.383: W/System.err(929): at java.util.HashMap$KeyIterator.next(HashMap.java:819)
01-30 00:27:54.383: W/System.err(929): at java.util.HashSet.<init>(HashSet.java:76)
01-30 00:27:54.383: W/System.err(929): at com.threed.jpct.TextureManager.getNames(TextureManager.java:413)
01-30 00:27:54.383: W/System.err(929): at com.threed.jpct.DeSerializer.deserialize(DeSerializer.java:136)
01-30 00:27:54.383: W/System.err(929): at com.threed.jpct.Loader.loadSerializedObjectArray(Loader.java:108)
01-30 00:27:54.383: W/System.err(929): at cz.chladek.mygame.util.ObjectLoader.loadObject(ObjectLoader.java:969)
01-30 00:27:54.383: W/System.err(929): at cz.chladek.mygame.util.ObjectLoader.access$3(ObjectLoader.java:955)
01-30 00:27:54.383: W/System.err(929): at cz.chladek.mygame.util.ObjectLoader$LoaderCore.run(ObjectLoader.java:206)
Title: Re: Loader - thread safe
Post by: EgonOlsen on January 30, 2013, 08:29:12 am
I looked at the Loader only when talking about thread safety. And while this one should be safe, the TextureManager might not...i'll have a look but i actually don't want to clutter it with synchronized all over the place....i'll report back this afternoon.
Title: Re: Loader - thread safe
Post by: EgonOlsen on January 30, 2013, 08:10:16 pm
I've update the beta jar with a version that adds more synchronization to the TextureManager. I tried to keep it as low a possible, so maybe i've missed something...please give it a try.
Title: Re: Loader - thread safe
Post by: Thomas. on January 30, 2013, 08:33:29 pm
It seems be fine now, thanks ;)