From 9291731fec7103301ba36511ceb4375f63170e5c Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 11 Dec 2011 04:47:27 +0100 Subject: Fix concurrency bug of GLProfile initialization ; Fix SharedResourceRunner 'dead' thread (Applets) GLDrawableFactory: - clarify: public getWasSharedContextCreated(..) -> protected createSharedResource(..) - add: getSharesResourceThread() GLProfile: - proper locking of initSingletion(..) path: - Use RecursiveThreadGroupLock and add/remove GLDrawableFactory's sharesResourceThread while creating it's the sharedResource. This simplifies and fixes GLProfile's locking code. - Fix and simplify initSingleton(boolean) API doc - mark it deprecated. - Add initSingleton() for controlled initialization only, pairing w/ shutdown(..) Remove initSingleton(boolean) calls in code and test! +++ Fix SharedResourceRunner 'dead' thread (Applets) In Applets, stopping an Applet makes the browser Java plugin interrupting and killing all related threads, including our SharedResourceRunner thread. - Validate whether the shared resource thread is alive - Catch interruption in shared resource thread and assume it's a kill signal - releaseSharedResource: clear devicesTried set --- .../test/junit/graph/TestRegionRendererNEWT01.java | 5 - .../test/junit/graph/TestTextRendererNEWT01.java | 5 - .../junit/graph/demos/GPURegionNewtDemo01.java | 1 - .../junit/graph/demos/GPURegionNewtDemo02.java | 1 - .../test/junit/graph/demos/GPUTextNewtDemo01.java | 1 - .../test/junit/graph/demos/GPUTextNewtDemo02.java | 1 - .../junit/graph/demos/GPUUISceneNewtDemo01.java | 1 - .../junit/graph/demos/GPUUISceneNewtDemo02.java | 1 - .../test/junit/graph/demos/ui/UINewtDemo01.java | 1 - .../test/junit/jogl/acore/TestGLDebug00NEWT.java | 5 - .../test/junit/jogl/acore/TestGLDebug01NEWT.java | 6 - .../junit/jogl/acore/TestInitConcurrentNEWT.java | 194 +++++++++++++++++++++ .../test/junit/jogl/acore/TestNVSwapGroupNEWT.java | 1 - .../jogl/acore/TestSharedContextListNEWT.java | 1 - .../jogl/acore/TestSharedContextListNEWT2.java | 1 - .../jogl/acore/TestSharedContextVBOES1NEWT.java | 1 - .../jogl/acore/TestSharedContextVBOES2NEWT.java | 1 - .../jogl/acore/TestSharedContextVBOES2NEWT2.java | 1 - .../junit/jogl/acore/TestShutdownCompleteAWT.java | 2 +- .../junit/jogl/acore/TestShutdownCompleteNEWT.java | 2 +- .../junit/jogl/acore/TestShutdownSharedAWT.java | 2 +- .../junit/jogl/acore/TestShutdownSharedNEWT.java | 2 +- .../test/junit/jogl/caps/TestTranslucencyNEWT.java | 1 - .../jogl/demos/es1/newt/TestGearsES1NEWT.java | 1 - .../jogl/demos/es1/newt/TestRedSquareES1NEWT.java | 1 - .../es2/newt/TestElektronenMultipliziererNEWT.java | 5 - .../jogl/demos/es2/newt/TestGearsES2NEWT.java | 1 - .../jogl/demos/es2/newt/TestRedSquareES2NEWT.java | 1 - .../junit/jogl/demos/gl2/awt/TestGearsAWT.java | 1 - .../junit/jogl/demos/gl2/newt/TestGearsNEWT.java | 1 - .../junit/jogl/drawable/TestDrawable01NEWT.java | 1 - .../test/junit/jogl/glsl/TestFBOMRTNEWT01.java | 5 - .../junit/jogl/glsl/TestGLSLShaderState01NEWT.java | 5 - .../junit/jogl/glsl/TestGLSLShaderState02NEWT.java | 5 - .../test/junit/jogl/glsl/TestGLSLSimple01NEWT.java | 6 - .../test/junit/jogl/glsl/TestRulerNEWT01.java | 5 - .../TestTransformFeedbackVaryingsBug407NEWT.java | 5 - ...TestSwingAWTRobotUsageBeforeJOGLInitBug411.java | 6 +- .../offscreen/TestOffscreen01GLPBufferNEWT.java | 1 - .../jogl/offscreen/TestOffscreen02BitmapNEWT.java | 1 - .../opengl/test/junit/jogl/swt/TestSWT01GLn.java | 1 - .../opengl/test/junit/jogl/swt/TestSWT02GLn.java | 1 - .../junit/newt/TestDisplayLifecycle01NEWT.java | 1 - .../junit/newt/TestDisplayLifecycle02NEWT.java | 1 - .../test/junit/newt/TestGLWindows00NEWT.java | 2 - .../test/junit/newt/TestGLWindows01NEWT.java | 2 - .../junit/newt/TestGLWindows02NEWTAnimated.java | 1 - .../test/junit/newt/TestRemoteGLWindows01NEWT.java | 10 +- .../test/junit/newt/TestScreenMode01NEWT.java | 3 +- .../test/junit/newt/TestScreenMode01bNEWT.java | 1 - .../test/junit/newt/TestScreenMode02NEWT.java | 1 - .../junit/newt/parenting/TestParenting01NEWT.java | 1 - .../junit/newt/parenting/TestParenting02NEWT.java | 1 - .../junit/newt/parenting/TestParenting03AWT.java | 4 - 54 files changed, 201 insertions(+), 117 deletions(-) create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrentNEWT.java (limited to 'src/test/com/jogamp/opengl') diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java b/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java index 55d3371c9..b6c3cc7fe 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java @@ -32,11 +32,6 @@ public class TestRegionRendererNEWT01 extends UITestCase { org.junit.runner.JUnitCore.main(tstname); } - @BeforeClass - public static void initClass() { - GLProfile.initSingleton(true); - } - static void destroyWindow(GLWindow window) { if(null!=window) { window.destroy(); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java index 9fd0c05e7..8f03af7c9 100755 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java @@ -35,11 +35,6 @@ public class TestTextRendererNEWT01 extends UITestCase { org.junit.runner.JUnitCore.main(tstname); } - @BeforeClass - public static void initClass() { - GLProfile.initSingleton(true); - } - static void destroyWindow(GLWindow window) { if(null!=window) { window.destroy(); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java index 5e0c266e6..160dc0ffe 100755 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java @@ -55,7 +55,6 @@ public class GPURegionNewtDemo01 { static final boolean TRACE = false; public static void main(String[] args) { - GLProfile.initSingleton(true); GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); caps.setAlphaBits(4); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java index f1db1ccdd..e7b5c73c5 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java @@ -52,7 +52,6 @@ public class GPURegionNewtDemo02 { static final boolean TRACE = false; public static void main(String[] args) { - GLProfile.initSingleton(true); GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); caps.setAlphaBits(4); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java index bcd60d441..d257f78fc 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java @@ -49,7 +49,6 @@ public class GPUTextNewtDemo01 { static final boolean TRACE = false; public static void main(String[] args) { - GLProfile.initSingleton(true); GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); caps.setAlphaBits(4); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java index 5981e7971..1b71cd781 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java @@ -57,7 +57,6 @@ public class GPUTextNewtDemo02 { static final boolean TRACE = false; public static void main(String[] args) { - GLProfile.initSingleton(true); GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java index 91f66875b..0563ab2cf 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java @@ -16,7 +16,6 @@ public class GPUUISceneNewtDemo01 { static final boolean TRACE = false; public static void main(String[] args) { - GLProfile.initSingleton(true); GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); caps.setAlphaBits(4); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java index a6cd770d1..4c8da139e 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java @@ -17,7 +17,6 @@ public class GPUUISceneNewtDemo02 { static final boolean TRACE = false; public static void main(String[] args) { - GLProfile.initSingleton(true); GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); caps.setAlphaBits(4); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java index 27b7ecc13..0577c5ff0 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java @@ -54,7 +54,6 @@ public class UINewtDemo01 { static final boolean TRACE = false; public static void main(String[] args) { - GLProfile.initSingleton(true); GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); caps.setAlphaBits(4); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug00NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug00NEWT.java index a42247b12..62e74466f 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug00NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug00NEWT.java @@ -55,11 +55,6 @@ public class TestGLDebug00NEWT extends UITestCase { static String dbgTstMsg0 = "Hello World"; static int dbgTstId0 = 42; - @BeforeClass - public static void initClass() { - // GLProfile.initSingleton(true); - } - public class WindowContext { public final Window window; public final GLContext context; diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug01NEWT.java index 6ab6714dc..f9b566c25 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug01NEWT.java @@ -41,7 +41,6 @@ import javax.media.opengl.GLRunnable; import org.junit.Assert; import org.junit.Test; -import org.junit.BeforeClass; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.test.junit.util.UITestCase; @@ -51,11 +50,6 @@ public class TestGLDebug01NEWT extends UITestCase { static String dbgTstMsg0 = "Hello World"; static int dbgTstId0 = 42; - @BeforeClass - public static void initClass() { - GLProfile.initSingleton(true); - } - GLWindow createWindow(GLProfile glp, boolean debugGL) { GLCapabilities caps = new GLCapabilities(glp); // diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrentNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrentNEWT.java new file mode 100644 index 000000000..b6c6e0a91 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrentNEWT.java @@ -0,0 +1,194 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.acore; + +import java.io.IOException; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import org.junit.Assert; +import org.junit.Test; + +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; + +public class TestInitConcurrentNEWT extends UITestCase { + + static long duration = 300; // ms + + public class JOGLTask implements Runnable { + private Object postSync; + private boolean done = false; + + public JOGLTask(Object postSync) { + this.postSync = postSync; + } + public void run() { + System.err.println(Thread.currentThread().getName()+" START"); + GLWindow glWindow = GLWindow.create(new GLCapabilities(GLProfile.getDefault())); + Assert.assertNotNull(glWindow); + glWindow.setTitle("Gears NEWT Test"); + + glWindow.addGLEventListener(new GearsES2(0)); + + Animator animator = new Animator(glWindow); + + glWindow.setSize(128, 128); + glWindow.setVisible(true); + animator.setUpdateFPSFrames(60, System.err); + animator.start(); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(true, glWindow.isVisible()); + Assert.assertEquals(true, glWindow.isNativeValid()); + Assert.assertEquals(true, glWindow.isRealized()); + + while(animator.isAnimating() && animator.getTotalFPSDuration()=0; i--) { + if(!tasks[i].done()) { + return false; + } + } + return true; + } + protected static String doneDump(JOGLTask[] tasks) { + StringBuffer sb = new StringBuffer(); + sb.append("["); + for(int i=0; i0) { + sb.append(", "); + } + sb.append(i).append(": ").append(tasks[i].done()); + } + sb.append("]"); + return sb.toString(); + } + + protected static boolean isDead(Thread[] threads) { + for(int i=threads.length-1; i>=0; i--) { + if(threads[i].isAlive()) { + return false; + } + } + return true; + } + protected static String isAliveDump(Thread[] threads) { + StringBuffer sb = new StringBuffer(); + sb.append("["); + for(int i=0; i0) { + sb.append(", "); + } + sb.append(i).append(": ").append(threads[i].isAlive()); + } + sb.append("]"); + return sb.toString(); + } + + protected void runJOGLTasks(int num) throws InterruptedException { + final String currentThreadName = Thread.currentThread().getName(); + final Object sync = new Object(); + final JOGLTask[] tasks = new JOGLTask[num]; + final Thread[] threads = new Thread[num]; + int i; + for(i=0; i