http://bugzilla.novell.com/show_bug.cgi?id=551228


           Summary: Race conditions despite locks with Mono 2.4 on IA-64
                    SGI Altix 4700
    Classification: Mono
           Product: Mono: Runtime
           Version: unspecified
          Platform: IA64
        OS/Version: SuSE Linux 10.0
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: misc
        AssignedTo: [email protected]
        ReportedBy: [email protected]
         QAContact: [email protected]
          Found By: ---


User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US)
AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.27 Safari/532.0

I am trying to get Mono 2.4 running on a SGI Altix 4700 (96-way Itanium 2
box) running SUSE Linux Enterprise Server 10.  It compiles successfully
using default configuration settings however upon testing (test program in
additional information) it fails at simple locking, that is, n threads
incrementing a shared counter produces race conditions.

I have tried;
 -> Changing "--with-tls" between both "__thread" and "pthread"
 -> Changing CFLAGS, CCASFLAGS, CXXFLAGS and FFLAGS to exclude
optimizations (removed -O2)
 -> Altering versions of glib (between glib-2.16.5 and glib-2.20.5) - there
is a gthread dependence but I am not sure how that impacts matters.

In addition the same behavior is present with Mono 1.2.2 (already on the
machine).  It should be noted that this test program works fine on a 8-way
AMD64 box producing correct results so I suspect it is something to do with the
IA-64 platform.

Reproducible: Always

Steps to Reproduce:
1. mono SharedCounter.exe 1000000 10

Actual Results:  
u...@host:~/code/tests> mono SharedCounter.exe 1000000 10
1000000 increments over 10 threads
Counter value: 999023

u...@host:~/code/tests> mono SharedCounter.exe 1000000 10
1000000 increments over 10 threads
Counter value: 999087

u...@host:~/code/tests> mono SharedCounter.exe 1000000 10
1000000 increments over 10 threads
Counter value: 999211

u...@host:~/code/tests> mono SharedCounter.exe 1000000 10
1000000 increments over 10 threads
Counter value: 999219

Expected Results:  
u...@host:~/code/tests> mono SharedCounter.exe 1000000 10
1000000 increments over 10 threads
Counter value: 1000000

Using: glib-2.20.5, libunwind-0.99, gcc version 4.1.2 20070115 (SUSE
Linux)

Test Program:
----------------------------

using System;
using System.Threading;

namespace Test
{
  public class SharedCounter
  {
    private static int increments;
    private static int n_threads;

    private static object shared_lock = new object();
    private static int shared_counter = 0;

    public static void Main(string[] args)
    {
      if (args.Length < 2) {
        Console.WriteLine("Usage: SharedCounter.exe <increments> <threads>");
        return;
      }

      increments = Convert.ToInt32(args[0]);
      n_threads = Convert.ToInt32(args[1]);

      // Make equally distributed
      increments = (increments / n_threads) * n_threads;

      Console.WriteLine("{0} increments over {1} threads", increments,
n_threads);

      Thread[] threads = new Thread[n_threads];
      for (int i = 0; i < n_threads; i++)
      {
        threads[i] = new Thread(Worker);
      }

      for (int i = 0; i < n_threads; i++)
      {
        threads[i].Start();
      }

      for (int i = 0; i < n_threads; i++)
      {
        threads[i].Join();
      }

      Console.WriteLine("Counter value: {0}", shared_counter);
    }

    public static void Worker()
    {
      int steps = increments / n_threads;
      for (int i = 0; i < steps; i++)
      {
        lock (shared_lock)
        {
          shared_counter++;
        }
      }
    }
  }
}

-- 
Configure bugmail: http://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.
_______________________________________________
mono-bugs maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-bugs

Reply via email to