[Mono-dev] ConcurrentStack with value type in 2.10

Rodrigo Kumpera kumpera at gmail.com
Mon Jul 23 12:32:12 UTC 2012


Hi Yuriy,

With how many cores and on what CPU did managed to reproduce this?
I'm running this on my 4 cores nehalem mac without any luck. I'll diff
ConcurrentStack
between 2.8 and 2.10 to see what could be.

On Sun, Jul 22, 2012 at 5:10 AM, Yuriy Solodkyy <yuriy at couldbedone.com>wrote:

> Hi,
>
> It looks like the ConcurrentStack does not work with big enough
> structures anymore.  12 bytes struct is enough to reproduce the
> problem occasionally, 16 bytes structure to reproduce it immediately.
> It worked fine in mono 2.8.  The following code shows that we may pop
> inconsistent structure from the stack from time to time.
>
> using System;
> using System.Collections.Concurrent;
> namespace CocurrentTest {
>         class MainClass {
>                 struct Data {
>                         public int A; public int B; public int C; public
> int D;
>                         public Data(int v) {
>                                 A = v; B = -v; C = v; D = -v;
>                         }
>                 }
>
>                 public static void Main (string[] args) {
>                         Console.WriteLine ("Hello World!");
>                         var data = new byte[1024 * 1024];
>                         var stack = new ConcurrentStack<Data> ();
>
>                         for (var i = 0; i < 50; i++) {
>
>                                 var thread = new System.Threading.Thread
> (v => {
>
>                                         var rnd = new Random ();
>                                         while (true) {
>                                                 int pushCount = rnd.Next
> (50);
>                                                 int popCount = rnd.Next
> (50);
>
>                                                 for (var k = 0; k <
> pushCount; k++) {
>
>
>                                                         var sample =
> new Data (rnd.Next(Int32.MaxValue));
>                                                         CheckSample
> (sample);
>
>                                                         stack.Push
> (sample);
>                                                 }
>
>                                                 for (var k = 0; k <
> popCount; k++) {
>                                                         Data
> retrievedSample = new Data();
>                                                         if
> (stack.TryPop (out retrievedSample)) {
>
> CheckSample (retrievedSample);
>                                                         }
>                                                 }
>                                         }
>                                 }
>                                 );
>
>                                 thread.Start ();
>                         }
>                 }
>
>                 static void CheckSample (Data sample){
>                         if (sample.A != -sample.B || sample.A !=
> sample.C || sample.B != sample.D)
>                                 throw new Exception (string.Format
> ("Invalid sample detected"));
>                 }
>         }
> }
>
>
> --
> Yuriy Solodkyy
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20120723/72b31e7c/attachment.html>


More information about the Mono-devel-list mailing list