Sync.sync(int) clears interrupted state

Started by bene_2808, October 07, 2015, 12:50:58

Previous topic - Next topic

bene_2808

Hi,

I don't know if here's the right place to post this, but I really had trouble with one detail of the Sync.sync(int) method, which does not have the best implementation, I think. Is this point documented or already mentioned? I don't know... ???

My render loop does not only exit when the display is close requested, an interruption of the thread also causes rendering to stop. But the interrupted state seemed never to be set, because the loop did not break, even if I was calling renderThread.interrupt() from outside. So I was searching and trying and searching for hours... To find out that Sync.sync(int) catches an interrupted exception, which clears the state, but does NOT tell the caller about it  :o >:(. Why not using a throws clause or a Boolean as return type?

Kai

That's probably a bug/design mistake in that Sync method, yes.
However, instead of using interrupts for inter-thread communication, you might prefer communication via shared memory using a volatile field, which you can query in your render loop (instead of querying Thread.isInterrupted() or catching an InterruptedException), and have a "terminator" thread set that field (instead of interrupting the render thread).
I think you can always propose a Pull Request on the LWJGL GitHub repository if you want the current behaviour to change soon. Spasi, the maintainer of LWJGL really accepts PRs quickly.