On 9/12/15 9:20 AM, Adam D. Ruppe via Digitalmars-d-learn wrote:
On Saturday, 12 September 2015 at 09:47:55 UTC, Jacob Carlborg wrote:
Well, if your D function doesn't use anything of the runtime I guess it's not
necessary.
Right. If you don't call into the threading system in the druntime, you should
be ok. Keep in mind
though that the GC uses the threads.... and the new expression, array literals,
array append, and
others use the GC.
Runtime.initialize is also what calls static and module constructors... and
might have
responsibility for fixing up dynamic casting of class objects in a shared lib
too, I'm not sure
about that.
But if you avoid the bulk of the runtime functions, indeed you can get away
without initializing it.
Just that null thread handle is likely to cause segfaults in places where you
might not expect if
you don't.
It is best to initialize it. Lots of C libraries need an init an teardown call,
so surely the Python
interop provides some solution for it. idk what it would be though.
I think it's safest to say (and it belongs in the spec somewhere) that executing D code before
initializing the runtime results in undefined behavior, or something along those lines. You can get
away with it in some circumstances, but it's at your own risk.