Gabriel M. Beddingfield wrote:

> However, what I was getting at is that there are about 2 threads at the
> first call of get_instance() and 5 at the second call.  What's to stop a
> developer from trying to call it from another thread?

These threads are:
- GUI
- logger (why a separate thread?)
- JACK thread (internal - doesn't call any Hydrogen code)
- JACK thread (audio?) or equivalent audio thread
- ALSA MIDI thread or equivalent MIDI thread

Out of these, only GUI, audio and MIDI are likely to call
get_instance(). The rest seems to be reasonably isolated from the
audio-related code :)

> Thanks for the example.  You're right.  What about the code below?
> private:
>     static A a;
> A A::a;

<rant>
Global objects in C++ are pure, concentrated evil ;-)

The problem is that you can't really be sure in what order they will be
created. For some cases (like the test program above), it's just fine.
For Hydrogen object... do you want audio engine stuff instantiated and
running before main() even starts?

Of course, they will work just fine on your machine and then they'll
break in unimaginable, cryptic ways on users' machines (because they may
just happen to use a different version of GCC than you). Or you can
spend hours trying to figure out why some trivial, obviously correct,
part of code doesn't work.

I'm speaking from experience - early versions of calf's synthesizer
plugins used to break in some applications on some machines for that
very reason. I've used static members for waveform table objects and
related stuff (FFT calculation etc.), thinking I'll get away with it
because they aren't really supposed to be used before application's
main() is called. How wrong I was!
</rant>

Krzysztof


------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Hydrogen-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hydrogen-devel

Reply via email to