Could you try master?<div><br></div><div><div>--</div>Jérémie Laval<div><div><a href="http://neteril.org" target="_blank">http://neteril.org</a></div></div><br>
<br><br><div class="gmail_quote">On Thu, Sep 20, 2012 at 2:38 PM, Greg Young <span dir="ltr"><<a href="mailto:gregoryyoung1@gmail.com" target="_blank">gregoryyoung1@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Here are some tests that show some of the failure modes of concurrent<br>
queue (all work in CLR impl)<br>
<br>
On my machine (8 cores within 1 second of running for all failures).<br>
The worst is the last one where anything larger than a reference gives<br>
partial reads.<br>
<br>
in gist if you prefer: <a href="https://gist.github.com/3755979" target="_blank">https://gist.github.com/3755979</a><br>
<br>
Unhandled Exception:<br>
System.NullReferenceException: Object reference not set to an instance<br>
of an object<br>
  at System.Collections.Concurrent.ConcurrentQueue`1[T].TryDequeue<br>
(System.Collections.Concurrent.T& result) [0x00000] in <filename<br>
unknown>:0<br>
  at ConsoleApplication1.Program+<TestMonoConcurrentQueueReference>c__AnonStorey1.<>m__0<br>
(System.Object x) [0x00000] in <filename unknown>:0<br>
  at System.Threading.Thread.StartInternal () [0x00000] in <filename unknown>:0<br>
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException:<br>
Object reference not set to an instance of an object<br>
  at System.Collections.Concurrent.ConcurrentQueue`1[T].TryDequeue<br>
(System.Collections.Concurrent.T& result) [0x00000] in <filename<br>
unknown>:0<br>
  at ConsoleApplication1.Program+<TestMonoConcurrentQueueReference>c__AnonStorey1.<>m__0<br>
(System.Object x) [0x00000] in <filename unknown>:0<br>
  at System.Threading.Thread.StartInternal () [0x00000] in <filename unknown>:0<br>
<br>
<br>
<br>
        private static void TestMonoConcurrentQueueReference()<br>
        {<br>
            var queue = new ConcurrentQueue<object>();<br>
            var waits = new List<AutoResetEvent>();<br>
            for (int i = 0; i < 5; i++)<br>
            {<br>
                int q = i;<br>
                waits.Add(new AutoResetEvent(false));<br>
                var t = new Thread(x =><br>
                {<br>
                    for (int j = 0; j < 100000000; j++)<br>
                    {<br>
                        if (j % 1000000 == 0) Console.Write(".");<br>
                        queue.Enqueue(new object());<br>
                        object item;<br>
                        if (queue.TryDequeue(out item))<br>
                        {<br>
<br>
                        }<br>
                    }<br>
                    waits[q].Set();<br>
                });<br>
                t.Start();<br>
            }<br>
            Console.WriteLine("waiting.");<br>
            waits.ForEach(x => x.WaitOne());<br>
            Console.WriteLine("done.");<br>
<br>
        }<br>
<br>
<br>
I end up in the else {} on try dequeue here don't think I should ever<br>
be allowed to (and dont end up there in MS impl)<br>
<br>
        struct TestStruct<br>
        {<br>
            public long X;<br>
            public long Y;<br>
<br>
            public TestStruct(long x, long y) : this()<br>
            {<br>
                X = x;<br>
                Y = y;<br>
            }<br>
        }<br>
<br>
        private static void TestMonoConcurrentQueueBiggerThanReference()<br>
        {<br>
            var queue = new ConcurrentQueue<TestStruct>();<br>
            var waits = new List<AutoResetEvent>();<br>
            for(int i=0;i<5;i++)<br>
            {<br>
                int q = i;<br>
                waits.Add(new AutoResetEvent(false));<br>
                var t = new Thread(x =><br>
                                       {<br>
                                           for(int j=0;j<100000000;j++)<br>
                                           {<br>
                                               if(j% 1000000 == 0)<br>
Console.Write(".");<br>
                                               queue.Enqueue(new<br>
TestStruct(0x11223344, 0x99887766));<br>
                                               TestStruct item;<br>
                                               if(queue.TryDequeue(out item))<br>
                                               {<br>
                                                   if(item.X !=<br>
0x11223344) throw new Exception("bad x");<br>
                                                   if(item.Y !=<br>
0x99887766) throw new Exception("bad y");<br>
                                               } else<br>
                                               {<br>
                                                   throw new<br>
Exception("unable to read."); <~~~~ should never hit this.<br>
                                               }<br>
                                           }<br>
                                           waits[q].Set();<br>
                                       });<br>
                t.Start();<br>
            }<br>
            Console.WriteLine("waiting.");<br>
            waits.ForEach(x => x.WaitOne());<br>
            Console.WriteLine("done.");<br>
<br>
        }<br>
<br>
<br>
For good measure lets take out the exception in the last about not<br>
being able to read when it should be able to (eg comment out the<br>
throw)<br>
<br>
Unhandled Exception:<br>
System.Exception: bad y<br>
  at ConsoleApplication1.Program+<TestMonoConcurrentQueueBiggerThanReference>c__AnonStorey3.<>m__2<br>
(System.Object x) [0x00000] in <filename unknown>:0<br>
  at System.Threading.Thread.StartInternal () [0x00000] in <filename unknown>:0<br>
<br>
Unhandled Exception:<br>
System.NullReferenceException: Object reference not set to an instance<br>
of an object<br>
  at System.Collections.Concurrent.ConcurrentQueue`1[ConsoleApplication1.Program+TestStruct].TryDequeue<br>
(ConsoleApplication1.TestStruct& result) [0x00000] in <filename<br>
unknown>:0<br>
  at ConsoleApplication1.Program+<TestMonoConcurrentQueueBiggerThanReference>c__AnonStorey3.<>m__2<br>
(System.Object x) [0x00000] in <filename unknown>:0<br>
  at System.Threading.Thread.StartInternal () [0x00000] in <filename unknown>:0<br>
<br>
Unhandled Exception:<br>
System.NullReferenceException: Object reference not set to an instance<br>
of an object<br>
  at System.Collections.Concurrent.ConcurrentQueue`1[ConsoleApplication1.Program+TestStruct].TryDequeue<br>
(ConsoleApplication1.TestStruct& result) [0x00000] in <filename<br>
unknown>:0<br>
  at ConsoleApplication1.Program+<TestMonoConcurrentQueueBiggerThanReference>c__AnonStorey3.<>m__2<br>
(System.Object x) [0x00000] in <filename unknown>:0<br>
  at System.Threading.Thread.StartInternal () [0x00000] in <filename unknown>:0<br>
<br>
Unhandled Exception:<br>
System.NullReferenceException: Object reference not set to an instance<br>
of an object<br>
  at System.Collections.Concurrent.ConcurrentQueue`1[ConsoleApplication1.Program+TestStruct].TryDequeue<br>
(ConsoleApplication1.TestStruct& result) [0x00000] in <filename<br>
unknown>:0<br>
  at ConsoleApplication1.Program+<TestMonoConcurrentQueueBiggerThanReference>c__AnonStorey3.<>m__2<br>
(System.Object x) [0x00000] in <filename unknown>:0<br>
  at System.Threading.Thread.StartInternal () [0x00000] in <filename unknown>:0<br>
<br>
Unhandled Exception:<br>
System.NullReferenceException: Object reference not set to an instance<br>
of an object<br>
  at System.Collections.Concurrent.ConcurrentQueue`1[ConsoleApplication1.Program+TestStruct].TryDequeue<br>
(ConsoleApplication1.TestStruct& result) [0x00000] in <filename<br>
unknown>:0<br>
  at ConsoleApplication1.Program+<TestMonoConcurrentQueueBiggerThanReference>c__AnonStorey3.<>m__2<br>
(System.Object x) [0x00000] in <filename unknown>:0<br>
  at System.Threading.Thread.StartInternal () [0x00000] in <filename unknown>:0<br>
[ERROR] FATAL UNHANDLED EXCEPTION: System.Exception: bad y<br>
  at ConsoleApplication1.Program+<TestMonoConcurrentQueueBiggerThanReference>c__AnonStorey3.<>m__2<br>
(System.Object x) [0x00000] in <filename unknown>:0<br>
  at System.Threading.Thread.StartInternal () [0x00000] in <filename unknown>:0<br>
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException:<br>
Object reference not set to an instance of an object<br>
  at System.Collections.Concurrent.ConcurrentQueue`1[ConsoleApplication1.Program+TestStruct].TryDequeue<br>
(ConsoleApplication1.TestStruct& result) [0x00000] in <filename<br>
unknown>:0<br>
  at ConsoleApplication1.Program+<TestMonoConcurrentQueueBiggerThanReference>c__AnonStorey3.<>m__2<br>
(System.Object x) [0x00000] in <filename unknown>:0<br>
  at System.Threading.Thread.StartInternal () [0x00000] in <filename unknown>:0<br>
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException:<br>
Object reference not set to an instance of an object<br>
  at System.Collections.Concurrent.ConcurrentQueue`1[ConsoleApplication1.Program+TestStruct].TryDequeue<br>
(ConsoleApplication1.TestStruct& result) [0x00000] in <filename<br>
unknown>:0<br>
  at ConsoleApplication1.Program+<TestMonoConcurrentQueueBiggerThanReference>c__AnonStorey3.<>m__2<br>
(System.Object x) [0x00000] in <filename unknown>:0<br>
  at System.Threading.Thread.StartInternal () [0x00000] in <filename unknown>:0<br>
<br>
<br>
    private static void TestMonoConcurrentQueueBiggerThanReference()<br>
        {<br>
            var queue = new ConcurrentQueue<TestStruct>();<br>
            var waits = new List<AutoResetEvent>();<br>
            for(int i=0;i<5;i++)<br>
            {<br>
                int q = i;<br>
                waits.Add(new AutoResetEvent(false));<br>
                var t = new Thread(x =><br>
                                       {<br>
                                           for(int j=0;j<100000000;j++)<br>
                                           {<br>
                                               if(j% 1000000 == 0)<br>
Console.Write(".");<br>
                                               queue.Enqueue(new<br>
TestStruct(0x11223344, 0x99887766));<br>
                                               TestStruct item;<br>
                                               if(queue.TryDequeue(out item))<br>
                                               {<br>
                                                   if(item.X !=<br>
0x11223344) throw new Exception("bad x");<br>
                                                   if(item.Y !=<br>
0x99887766) throw new Exception("bad y");<br>
                                               } else<br>
                                               {<br>
                                                   //throw new<br>
Exception("unable to read."); <~~~~ should never hit this.<br>
                                               }<br>
                                           }<br>
                                           waits[q].Set();<br>
                                       });<br>
                t.Start();<br>
            }<br>
            Console.WriteLine("waiting.");<br>
            waits.ForEach(x => x.WaitOne());<br>
            Console.WriteLine("done.");<br>
<br>
        }<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Le doute n'est pas une condition agréable, mais la certitude est absurde.<br>
_______________________________________________<br>
Mono-devel-list mailing list<br>
<a href="mailto:Mono-devel-list@lists.ximian.com">Mono-devel-list@lists.ximian.com</a><br>
<a href="http://lists.ximian.com/mailman/listinfo/mono-devel-list" target="_blank">http://lists.ximian.com/mailman/listinfo/mono-devel-list</a><br>
</font></span></blockquote></div><br></div>