[omniORB] modifications to omni_thread
David Riddoch
djr@uk.research.att.com
Mon, 10 Jul 2000 13:52:08 +0100 (BST)
Jonathan,
init_t is not a sub-class of omni_thread, just a member. A static
instance will be created in every compilation unit which includes
omni_thread.h. The omni_thread::init_t::init_t() constructor is thus
called at static initialisation time (not when threads are created) and
thus the calls are guarenteed to be serialised.
The purpose of this is to ensure that the omni_thread library is properly
initialised before it is used. The omni_thread library is frequently used
before main() is called, for example to initialise static mutexes and
condition variables.
Cheers,
David
On Fri, 7 Jul 2000, Jonathan Clark wrote:
> RE: [omniORB] memory allocation/free under Win32The omni_thread class has a
> sub-class called init_t whose purpose is to initialize the
> thread system. The way it is declared, init_t will be executed every time a
> thread is
> created - when really it is only needed once. To deal with this, you have a
> check at
> init_t::init_t()
>
> if (count++ != 0) // only do it once however many objects get created.
> return;
>
> In some pathological cases this check could fail (it's not thread safe).
> Unless omni_threads
> are always created from the main thread? Also init_t() calls new() to
> allocate a omni_mutex
> and a omni_thread. Because there is a global instance of init_t declared,
> new() will be called
> before main. This is bad (see my previous email about memory allocation).
> So - to fix both,
> I removed init_t from the omni_thread class and created a static member
> function
> omni_thread::global_init() function that is called from ORB_init.
>
> Is there anything that requires the thread system to be initialized before
> ORB_init?? From
> my examination of the source, it doesn't look like it...
>
> One final note, it looks like the objects created by init_t are never
> destroyed. Only a 2 object leak,
> so no big deal - but thought you might want to know.
>
> Jonathan
>
> btw, should I report things like this to the list or directly to the AT&T
> staff?
The list is fine.