[Mono-list] Re: [Gtk-sharp-list] ThreadNotify (A bug in Queue.Dequeue method)

Pablo Baena pbaena@uol.com.ar
12 Oct 2002 03:05:27 +0000


--=-EX51l+aqIlnlF7i904ay
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Followed your advise and tried this:


namespace test
{
	using System;
	using System.IO;
	using System.Runtime.InteropServices;
	using System.Diagnostics;
	using System.Collections;
=09
	class test
	{
		public static void Main(string[] args)
		{
			Queue queue =3D new Queue();
			string tmp;

			for (int i=3D0;i<50;i++) {
				queue.Enqueue("Data #"+i);
			}
			/*
			foreach ( System.Object item in queue ) {
				Console.WriteLine("showing: {0}",item);
			}
			*/
			while(queue.Count>0){
				tmp =3D (string) queue.Dequeue();
				Console.WriteLine("showing: {0}",tmp);=09
			}
		=09
		}
	}
}


Problem is, the output I get is:


showing: Data #0
showing: Data #1
showing: Data #2
showing: Data #3
showing: Data #4
showing: Data #5
showing: Data #6
showing: Data #7
showing: Data #8
showing: Data #9
showing: Data #10
showing: Data #11
showing: Data #12
showing: Data #13
showing: Data #14
showing: Data #15
showing: Data #0
showing: Data #1
showing: Data #2
showing: Data #3
showing: Data #4
showing: Data #5
showing: Data #6
showing: Data #7
showing: Data #8
showing: Data #9
showing: Data #10
showing: Data #11
showing: Data #12
showing: Data #13
showing: Data #14
showing: Data #15
showing: Data #0
showing: Data #1
showing: Data #2
showing: Data #3
showing: Data #4
showing: Data #5
showing: Data #6
showing: Data #7
showing: Data #8
showing: Data #9
showing: Data #10
showing: Data #11
showing: Data #12
showing: Data #13
showing: Data #14
showing: Data #15
showing: Data #0
showing: Data #1


On Sat, 2002-10-12 at 05:15, Vladimir Vukicevic wrote:

    On Fri, 2002-10-11 at 19:44, Pablo Baena wrote:
    > The last problem I showed here is not ThreadNotify's fault. Seems to
    > be a bug in Queue.Dequeue.=20
    > If you look at the output of the test, you will notice it isn't
    > accurate to the data in the queue when you use Dequeue, but the
    > commented part with foreach works fine.=20
   =20
    This test seems to work fine for me... I have it putting in the lines o=
f
    data and then dequeueing the same lines in the same order.  The lock
    statements are necessary when you use the queue between threads; you
    want to lock (queue) { operations_on_queue_here; }, since the queue
    itself doesn't do any locking.  What output are you seeing that's
    broken?  I'd also suggest not using ls for a test case, because of the
    possibility of ls sending bizzarely formatted output that could be
    confusing the reader (the chances of this are almost zero, but still..)
   =20
    	- Vlad
   =20
    --=20
    Vladimir Vukicevic <vladimir@pobox.com>



________________________________________________________________________


<Tetsuo> la vida es muy ironica vio?
<Ranma> sip la verdad que se nos esta cagando de risa!
<Ranma> y la voy a cagar a pi=F1as

--=-EX51l+aqIlnlF7i904ay
Content-Type: text/html; charset=utf-8

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/1.0.4">
</HEAD>
<BODY>
Followed your advise and tried this:
<BR>

<PRE>namespace test
{
	using System;
	using System.IO;
	using System.Runtime.InteropServices;
	using System.Diagnostics;
	using System.Collections;
	
	class test
	{
		public static void Main(string[] args)
		{
			Queue queue = new Queue();
			string tmp;

			for (int i=0;i&lt;50;i++) {
				queue.Enqueue(&quot;Data #&quot;+i);
			}
			/*
			foreach ( System.Object item in queue ) {
				Console.WriteLine(&quot;showing: {0}&quot;,item);
			}
			*/
			while(queue.Count&gt;0){
				tmp = (string) queue.Dequeue();
				Console.WriteLine(&quot;showing: {0}&quot;,tmp);	
			}
			
		}
	}
}</PRE>

<BR>
Problem is, the output I get is:
<BR>

<PRE>showing: Data #0
showing: Data #1
showing: Data #2
showing: Data #3
showing: Data #4
showing: Data #5
showing: Data #6
showing: Data #7
showing: Data #8
showing: Data #9
showing: Data #10
showing: Data #11
showing: Data #12
showing: Data #13
showing: Data #14
showing: Data #15
showing: Data #0
showing: Data #1
showing: Data #2
showing: Data #3
showing: Data #4
showing: Data #5
showing: Data #6
showing: Data #7
showing: Data #8
showing: Data #9
showing: Data #10
showing: Data #11
showing: Data #12
showing: Data #13
showing: Data #14
showing: Data #15
showing: Data #0
showing: Data #1
showing: Data #2
showing: Data #3
showing: Data #4
showing: Data #5
showing: Data #6
showing: Data #7
showing: Data #8
showing: Data #9
showing: Data #10
showing: Data #11
showing: Data #12
showing: Data #13
showing: Data #14
showing: Data #15
showing: Data #0
showing: Data #1</PRE>

<BR>
On Sat, 2002-10-12 at 05:15, Vladimir Vukicevic wrote:
    <BLOCKQUOTE>
<PRE><FONT COLOR="#737373"><FONT SIZE="3"><I>On Fri, 2002-10-11 at 19:44, Pablo Baena wrote:</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>&gt; The last problem I showed here is not ThreadNotify's fault. Seems to</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>&gt; be a bug in Queue.Dequeue. </FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>&gt; If you look at the output of the test, you will notice it isn't</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>&gt; accurate to the data in the queue when you use Dequeue, but the</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>&gt; commented part with foreach works fine. </FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I></FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>This test seems to work fine for me... I have it putting in the lines of</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>data and then dequeueing the same lines in the same order.  The lock</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>statements are necessary when you use the queue between threads; you</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>want to lock (queue) { operations_on_queue_here; }, since the queue</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>itself doesn't do any locking.  What output are you seeing that's</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>broken?  I'd also suggest not using ls for a test case, because of the</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>possibility of ls sending bizzarely formatted output that could be</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>confusing the reader (the chances of this are almost zero, but still..)</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I></FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>	- Vlad</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I></FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>-- </FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>Vladimir Vukicevic &lt;</FONT></FONT></I><A HREF="mailto:vladimir@pobox.com"><FONT SIZE="3"><I>vladimir@pobox.com</FONT></I></A><FONT COLOR="#737373"><FONT SIZE="3"><I>&gt;</FONT></FONT></I></PRE>
    </BLOCKQUOTE>
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>

<BR>

<HR>

<BR>

<PRE>&lt;Tetsuo&gt; la vida es muy ironica vio?
&lt;Ranma&gt; sip la verdad que se nos esta cagando de risa!
&lt;Ranma&gt; y la voy a cagar a pi&#241;as</PRE>
</TD>
</TR>
</TABLE>

</BODY>
</HTML>

--=-EX51l+aqIlnlF7i904ay--