[Mono-dev] ConcurrentStack with value type in 2.10

Gonzalo Paniagua Javier gonzalo.mono at gmail.com
Sun Jul 22 16:36:57 UTC 2012


I have added bug #6229 with this information:
https://bugzilla.xamarin.com/show_bug.cgi?id=6229

-Gonzalo

On Sun, Jul 22, 2012 at 4: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


More information about the Mono-devel-list mailing list