Loader - thread safe

Started by Thomas., January 26, 2013, 04:23:30 PM

Previous topic - Next topic

Thomas.

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

EgonOlsen

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


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?

Thomas.

#2
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...

EgonOlsen

No, not possible. It has to happen in the thread that is associated with the gl context.

Thomas.

I got this message when I was loading objects

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)

EgonOlsen

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.

EgonOlsen

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.

Thomas.