[omniORB] modifications to omni_thread

Jonathan Clark jc@jonathanclark.com
Fri, 7 Jul 2000 13:38:05 -0700


This is a multi-part message in MIME format.

------=_NextPart_000_0000_01BFE818.94D09520
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

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?

------=_NextPart_000_0000_01BFE818.94D09520
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>RE: [omniORB] memory allocation/free under =
Win32</TITLE>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4030.2400" name=3DGENERATOR></HEAD>
<BODY>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =
size=3D2>The=20
omni_thread class has a sub-class called init_t whose purpose is to =
initialize=20
the</FONT></SPAN></DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =
size=3D2>thread=20
system.&nbsp; The way it is declared, init_t will be executed every time =
a=20
thread is</FONT></SPAN></DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =

size=3D2>created - when really it is only needed once.&nbsp; To deal =
with this,=20
you have a check at</FONT></SPAN></DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =

size=3D2>init_t::init_t()</FONT></SPAN></DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =

size=3D2>&nbsp;&nbsp;&nbsp; if (count++ !=3D 0)&nbsp;// only do it once =
however many=20
objects get created.<BR>&nbsp; &nbsp;&nbsp; =
&nbsp;return;</FONT></SPAN></DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =
size=3D2>In=20
some pathological cases&nbsp; </FONT></SPAN><SPAN =
class=3D464353919-07072000><FONT=20
face=3DArial color=3D#0000ff size=3D2>this check could =
</FONT></SPAN><SPAN=20
class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =
size=3D2>fail (it's not=20
thread safe).&nbsp; Unless omni_threads</FONT></SPAN></DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =
size=3D2>are=20
always created from the main thread?&nbsp; </FONT></SPAN><SPAN=20
class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =
size=3D2>Also init_t()=20
calls new() to allocate a omni_mutex </FONT></SPAN></DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =
size=3D2>and a=20
omni_thread.&nbsp; Because there is a&nbsp;</FONT></SPAN><SPAN=20
class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =
size=3D2>global instance=20
</FONT></SPAN><SPAN class=3D464353919-07072000><FONT face=3DArial =
color=3D#0000ff=20
size=3D2>of init_t declared, new() will be called </FONT></SPAN></DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =
size=3D2>before=20
main.&nbsp; This is bad (see my previous email </FONT></SPAN><SPAN=20
class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =
size=3D2>about memory=20
allocation).&nbsp; So - to fix both, </FONT></SPAN></DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =
size=3D2>I=20
removed init_t from the omni_thread class </FONT></SPAN><SPAN=20
class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =
size=3D2>and created a=20
static member function </FONT></SPAN></DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =

size=3D2>omni_thread::global_init() function that is called from =
ORB_init.&nbsp;=20
</FONT></SPAN></DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =
size=3D2>Is=20
there anything that </FONT></SPAN><SPAN class=3D464353919-07072000><FONT =

face=3DArial color=3D#0000ff size=3D2>requires the thread system to be =
initialized=20
before ORB_init??&nbsp; From</FONT></SPAN></DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =
size=3D2>my=20
examination of the source, it doesn't look like =
it...</FONT></SPAN></DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =
size=3D2>One=20
final note, it looks like the&nbsp;objects created by init_t&nbsp;are =
never=20
destroyed.&nbsp; Only a 2 object leak,</FONT></SPAN></DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =
size=3D2>so no=20
big deal - but thought you might want to know.</FONT></SPAN></DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =

size=3D2>Jonathan</FONT></SPAN></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2></FONT>&nbsp;</DIV>
<DIV><SPAN class=3D464353919-07072000><FONT face=3DArial color=3D#0000ff =
size=3D2>btw,=20
should I report things like this to the list or directly to the AT&amp;T =

staff?</FONT></SPAN></DIV></BODY></HTML>

------=_NextPart_000_0000_01BFE818.94D09520--