[Mono-list] 3 TODOs in Threading namespace almost completed

Jaroslaw Kowalski jaak@zd.com.pl
Tue, 16 Mar 2004 11:15:23 +0100


This is a multi-part message in MIME format.

------=_NextPart_000_0108_01C40B47.FA060AA0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Looks like there's a regression in your code when compared to the =
current CVS.

In Timer.Runner.Dispose(bool) it is possible that you call wait.Set() on =
an already-disposed "wait" object which holds unmanaged resource.

Consider this scenario:

1. You create new Runner()
2. Runner() constructor creates a new ManualResetEvent()
3. ...some time passes...
4. Both Runner and ManualResetEvent become garbage so they are added to =
the finalization queue
5. ManualResetEvent gets finalized first
6. You call "wait.Set()" on it when finalizing Runner which leads to =
some strange results.

This causes the possible deadlocks when unloading appdomains and was =
reported as a bug and fixed here:

http://bugzilla.ximian.com/show_bug.cgi?id=3D54980

BTW. Why is that Thread.Sleep(100) needed there ? This looks like a huge =
hack.

Jarek
  ----- Original Message -----=20
  From: Mr. Deepak P N=20
  To: mono-list@lists.ximian.com ; gonzalo@ximian.com ; dick@ximian.com=20
  Sent: Tuesday, March 16, 2004 10:37 AM
  Subject: [Mono-list] 3 TODOs in Threading namespace almost completed


  Hi,
            I have implemented the Change() method[ false return value ] =
and the Dispose() method, which was incomplete.

  Please inform me whether this is fine or it needs any other =
modification.
  [Although this gave raise to another todo, which I am working on].


       Since the WaitHandle class is an abstract class, we obviously =
cannot instantiate an instance of its type.  So, how can there be an =
implementation of a constructor.

       Even the MSDN documentation seems to mislead us by saying that =
WaitHadle() constructor "Initializes a new instance of the WaitHandle =
class".

       I think the TODO does not exist.

  I am interested in completing all the TODOs in "System.Threading" =
namespace.

  P.S: Timer.cs attached

  Best Regards,
  Deepak.




   
------=_NextPart_000_0108_01C40B47.FA060AA0
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>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1400" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Looks like there's a regression in your code when =
compared to=20
the current CVS.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>In Timer.Runner.Dispose(bool) it is possible that =
you call=20
wait.Set() on an already-disposed "wait" object which holds unmanaged=20
resource.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Consider this scenario:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>1. You create new Runner()</FONT></DIV>
<DIV><FONT size=3D2>2. Runner() constructor creates a new=20
ManualResetEvent()</FONT></DIV>
<DIV><FONT size=3D2>3. ...some time passes...</FONT></DIV>
<DIV><FONT size=3D2>4. Both Runner and ManualResetEvent become garbage =
so they are=20
added to the finalization queue</FONT></DIV>
<DIV><FONT size=3D2>5. ManualResetEvent gets finalized =
first</FONT></DIV>
<DIV><FONT size=3D2>6. You call "wait.Set()" on it when finalizing =
Runner which=20
leads to some strange results.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>This causes the possible deadlocks when unloading =
appdomains=20
and was reported as a bug and fixed here:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2><A=20
href=3D"http://bugzilla.ximian.com/show_bug.cgi?id=3D54980">http://bugzil=
la.ximian.com/show_bug.cgi?id=3D54980</A></FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>BTW. Why is that Thread.Sleep(100) needed there ? =
This looks=20
like a huge hack.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Jarek</FONT></DIV>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Ddeepakparasam@rediffmail.com=20
  href=3D"mailto:deepakparasam@rediffmail.com">Mr. Deepak P N</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3Dmono-list@lists.ximian.com=20
  =
href=3D"mailto:mono-list@lists.ximian.com">mono-list@lists.ximian.com</A>=
 ; <A=20
  title=3Dgonzalo@ximian.com=20
  href=3D"mailto:gonzalo@ximian.com">gonzalo@ximian.com</A> ; <A=20
  title=3Ddick@ximian.com =
href=3D"mailto:dick@ximian.com">dick@ximian.com</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Tuesday, March 16, 2004 =
10:37=20
  AM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Mono-list] 3 TODOs in =
Threading=20
  namespace almost completed</DIV>
  <DIV><BR></DIV>
  <P>Hi,<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; I have implemented the =
Change()=20
  method[ false return value ] and the Dispose() method, which was=20
  incomplete.<BR><BR>Please inform me whether this is fine or it needs =
any other=20
  modification.<BR>[Although this gave raise to another todo, which I am =
working=20
  on].<BR><BR><BR>&nbsp; &nbsp; &nbsp;Since the WaitHandle class is an =
abstract=20
  class, we obviously cannot instantiate an instance of its type.&nbsp; =
So, how=20
  can there be an implementation of a constructor.<BR><BR>&nbsp; &nbsp;=20
  &nbsp;Even the MSDN documentation seems to mislead us by saying that=20
  WaitHadle() constructor =93Initializes a new instance of the =
WaitHandle=20
  class=94.<BR><BR>&nbsp; &nbsp; &nbsp;I think the TODO does not =
exist.<BR><BR>I=20
  am interested in completing all the TODOs in =93System.Threading=94=20
  namespace.<BR><BR>P.S: Timer.cs attached<BR><BR>Best=20
  Regards,<BR>Deepak.<BR></P><BR><BR><A=20
  href=3D"http://clients.rediff.com/signature/track_sig.asp" =
target=3D_blank><IMG=20
  height=3D74 hspace=3D0=20
  =
src=3D"http://ads.rediff.com/RealMedia/ads/adstream_nx.cgi/www.rediffmail=
.com/inbox.htm@Bottom"=20
  width=3D496 border=3D0></A> </BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0108_01C40B47.FA060AA0--