On OSX 10.9.5, running multiple GLAutoDrawables each within their
own Animator while GLContext sharing one common master thread
w/o locking - leads to a crash.
- Section Overview
- Paragraph 5
"Multi-threaded use of OpenGL contexts in a "share group" allow
sharing of objects such as textures and programs. Such sharing in
conjunction with concurrent OpenGL commands stream execution by two
or more contexts introduces hazards whereby one context can change
objects in ways that can cause buffer overflows for another context's
On OSX 10.9.5 using multiple GLContext, sharing a common master,
each rendering in their own thread (multithreading),
causes a crash.
I added experimental locking of the ShareSet in
which removes the crash.
However, such ShareSet locking is too invasive:
- may deadlocks multithreaded creation/usage,
e.g. in GLMediaPlayerImpl (Animator vs StreamWorker)
- removes benefits of multithreading usage
- OSX 10.9.5 not always crashes utilizing multithreaded shared contexts
- GLMediaPlayerImpl does not crash due to proper use of RingBuffer*,
which adds implicit lock-free object queuing (put/take).
- GearsES2 does crash due to concurrent draw commands of the 'slaves'
using the 'master' VBO objects,
even though such objects are created before concurrent read-only access
and immutable afterwards.
- Adding new GLRendererQuirk.NeedSharedObjectSync
- _NOT_ handling this quirk in our API directly,
i.e. not implementing above mentioned ShareSet locking.
- User is required to synchronize access of shared GL objects,
for drivers exposing GLRendererQuirk.NeedSharedObjectSync
- Adding a note to GLSharedContextSetter
GLSharedContextSetter#synchronization GL Object Synchronization
Usually synchronization of shared GL objects should not be required,
if the shared GL objects are created and immutable before concurrent usage.
However, using drivers exposing GLRendererQuirks.NeedSharedObjectSync
always require the user to synchronize access of shared GL objects.
Synchronization can be avoided if accessing the shared GL objects
exclusively via a queue or com.jogamp.common.util.Ringbuffer,
see GLMediaPlayerImpl as an example.
(*) == preliminary commits for unit testing
and providing a clean patch addressing the issue only.
Shared Gears* Unit Tests: Align all 3 Gears* implementation
to use a shared Gears* object
Bug 1088: Fix ant test target 'junit.run.sharedctx':
Reuse generalized 'generic.junit.run.newt.headless', 'generic.junit.run.awt', ..
GLRendererQuirks: Align wording in API doc
Add GLRendererQuirks.NeedSharedObjectSync; Tests: Synchronize GL objects if GLRendererQuirks.NeedSharedObjectSync is set.
^^ actual fix, as described.