[Mono-bugs] [Bug 662381] C# lock () fails on latest Mono runtimes

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Jan 6 01:01:44 EST 2011


https://bugzilla.novell.com/show_bug.cgi?id=662381

https://bugzilla.novell.com/show_bug.cgi?id=662381#c12


--- Comment #12 from John Costella <john.costella at petermac.org> 2011-01-06 06:01:43 UTC ---
OK, I have finally boiled it down to a simple example:


using System;
using System.Threading.Tasks;

class MainClass
{
    public static void Main (string[] args)
    {
        for (var run = 0; run < 100; run++) Parallel.For(0, 10, i => Foo());
    }

    static void Foo()
    {
        lock (num)
        {
            num[0] = 0;
            Parallel.For(0, 10, k => {});
            if (num[0] > 0) Console.WriteLine("Error: num[0] is " + num[0] + "
instead of 0");
            num[0]++;
        }
    }
    static int[] num = new int[1];
}

Sample output:


Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 2 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 2 instead of 0
Error: num[0] is 3 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 2 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 2 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 2 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 2 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 1 instead of 0
Error: num[0] is 2 instead of 0

The inner Parallel.For() causes the lock to fail.

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list