Threading.invokeOnOpenGLThread blocking?

Just a quick question regarding Threading.invokeOnOpenGLThread(Runnable r):
Is this method blocking (does it wait until the Runnable has finished executing)?

If so, it would be nice if this behavior was documented (given it will stay that way).
If not, it would be nice if there was a blocking variant of this method.

To check, put a Thread.sleep(10*1000) in that runnable, and a System.out right after invokeOnOpenGLThread

[quote]To check, put a Thread.sleep(10*1000) in that runnable, and a System.out right after invokeOnOpenGLThread
[/quote]
Thanks for your quick answer.

Actually my concern is not whether the method is actually blocking in the current implementation, but rather that - whatever the behavior is - it should be documented in order to give a strong indication that this behavior will not change with future releases.

In case it is not blocking, and you want it to block, do this:


final boolean[] flag = new boolean[]{false};
Threading.invokeOnOpenGLThread(new Runnable(){ public void run(){ ... your rendering code ... }});
Threading.invokeOnOpenGLThread(new Runnable(){
      public void run(){ try { synchronized(flag){ flag[0]=true; flag.notify();}  } catch(Exception exc) { /* ignore */ }}
});

while(!flag[0])
   try { synchronized(flag){ flag.wait();}  } catch(Exception exc) { /* ignore */ }

At least this blocks, whether or not the future implementation blocks :stuck_out_tongue:

I see what you are trying to do… but that code example is broken.
If the opengl render thread invokes the body of the 2nd Runnable inbetween the calling Thread executing:

while(!flag[0])

and

try { synchronized(flag){ flag.wait();}  } catch(Exception exc) { /* ignore */ }

The calling Thread will block indefinitely at the flag.wait(), as it will already have received the flag.notify() that was intended to wake it up.

bah, synchronized-block-scope-screwup :-[

Sorry the documentation is unclear. I’ve filed Issue 353 to track it. Yes, it is blocking and yes, you can rely on this.