Hi Dirk,

Dirk Reiners wrote:
On Wed, 2004-04-28 at 17:34, Chad Austin wrote:
I've wondered about this too...  More specifically, I was wondering if
osgInit and osgExit could be called multiple times in a row, as long as there is one exit for each init:

osgInit(...)
  osgInit(...)
  ...
  osgExit()
osgExit()

The code didn't look like it could handle that, but it would really
come in handy... (Ideally, it would be nice if there was no such thing as osgInit and osgExit, but it doesn't seem like that's feasible :)


No, that's not going to work, init and exit are one-shot things. Where
would it come in handy? I can't really imagine what you'd need this for
right now. ;)

For an example close to home, the OpenSG Switcher calls osgInit whenever any application's apiInit() is called, and osgExit on apiExit(). There was also another situation (that I now can't remember) where I wished osgInit() and osgExit() could be called multiple times. If some basic refcounting logic were added, this could become a supported call sequence.

bool atexitRegistered = false;
int initCount = 0;

osgInit() {
    if (!atexitRegistered) {
        // supports current behavior of osgInit() with no explicit osgExit()
        atexit(function to check initCount and do shutdown)
    }

    if (initCount++ == 0) {
        // ...
    }
}

osgExit() {
    if (--initCount == 0) {
        // ...
    }
}

COM uses a system like that with CoInitialize() and CoUninitialize().

I wouldn't mind being the one writing the patch and testing if nobody sees any problems with the above.

And unless we get more influence on the startup sequence of C++, we will
need osgInit. The primary use is to call the initialize functions of the
type system. Given that we store the complete list of fields in each
type, all the base types have to be initialized before that, and the
undefined initialization order f static C++ instances makes that a
little hard. Exit is probably not as critical, but init is hard to get
around.

Fair enough.

Cheers,
Chad



-------------------------------------------------------
This SF.Net email is sponsored by: SourceForge.net Broadband
Sign-up now for SourceForge Broadband and get the fastest
6.0/768 connection for only $19.95/mo for the first 3 months!
http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to