Hi Krzysztof,

When it comes to concurrency my knowledge is mostly based on university 
lectures, so i can't speak of implementation details at the moment :(

I would go for the Fix which Torben Hohn suggested. That would be the 
most "robust" solution. We don't have to rely on the driver's code. And 
it would be easy to port this code to other singleton objects in 
hydrogen ( but i don't think the problem exists there because most of 
them aren't doing much work in the constructor).
And of course, it is less error prone to fix a thing in a single point 
then having to fix a number of drivers.

But this is just my theoretical opinion, maybe its total crap when it is 
used in practice.
- Sebastian

Krzysztof Foltman wrote:
> Hi all,
>
> I have a possible fix for issue #37 (crash on startup). After closer 
> inspection (attached to the issue :) ), it looks like the reason 
> Hydrogen crashes on startup is because ALSA MIDI driver calls 
> Hydrogen::get_instance() while first Hydrogen::get_instance() (which 
> creates the singleton object) is still running. This causes two 
> Hydrogen objects to be created, which is responsible for the crash.
>
> First fix (mine) is very simple - set the __instance variable before 
> the drivers are started. See: hydrogen-crash-patch.diff - the drawback 
> is that something (MIDI or audio driver) may still potentially call 
> things on Hydrogen object before it's fully constructed.
>
> Second fix: Torben Hohn suggested on #lad IRC channel to use a mutex 
> in get_instance() to prevent situations like this. I've found a more 
> lightweight way - ensuring that MIDI thread doesn't proceed until the 
> drivers are fully set up. It's actually quite easy to do, as 
> startAudioDrivers locks the audio engine until it completes. Because 
> MIDI thread is started from that function (with audio engine mutex 
> locked), it's enough to lock and unlock the audio engine once from 
> MIDI thread (so it doesn't start doing anything on Hydrogen object 
> until driver initialization stuff completes and unlocks the mutex).
>
> I did this in the second patch (hydrogen-crash-patch-improvement) for 
> ALSA MIDI only, but the same fix should probably be applied to other 
> MIDI drivers (and possibly ALSA audio driver as well, just to be safe 
> - there is no point in doing any processing until the driver 
> initialization is complete).
>
> More details (much more than anyone is willing to digest, I guess) are 
> added as comments to the ticket.
>
> Any comments/suggestions/mistakes in the analysis above? (I'm still 
> mostly unfamiliar with Hydrogen code, so might have missed something 
> important)
>
> Krzysztof
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
> software. With Adobe AIR, Ajax developers can use existing skills and code to
> build responsive, highly engaging applications that combine the power of local
> resources and data with the reach of the web. Download the Adobe AIR SDK and
> Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
> ------------------------------------------------------------------------
>
> _______________________________________________
> Hydrogen-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/hydrogen-devel


------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
Hydrogen-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hydrogen-devel

Reply via email to