[Mono-bugs] [Bug 551228] Race conditions despite locks with Mono 2.4 on IA-64 SGI Altix 4700

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Oct 29 23:41:05 EDT 2009


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

User darryl at cain.com.au added comment
http://bugzilla.novell.com/show_bug.cgi?id=551228#c2





--- Comment #2 from Darryl Cain <darryl at cain.com.au>  2009-10-29 21:41:03 MDT ---
I changed the test program to be;

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

 Thread.Sleep(1000);

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

and still no difference (see below for results with two threads).  I don't
believe there is any problem with the joins.

user at host:~/code/tests> mono SharedCounter.exe 1000000 2
1000000 increments over 2 threads
Counter value: 999744

user at host:~/code/tests> mono SharedCounter.exe 1000000 2
1000000 increments over 2 threads
Counter value: 999862

user at host:~/code/tests> mono SharedCounter.exe 1000000 2
1000000 increments over 2 threads
Counter value: 999821

Oddly, after some more testing I have found that if I change;

private static object shared_lock = new object();

to

private static readonly object shared_lock = new object();

I get the correct and desired results (same results as x86 and AMD64 systems
without readonly).

user at host:~/code/tests> mono SharedCounter.exe 1000000 2
1000000 increments over 2 threads
Counter value: 1000000

user at host:~/code/tests> mono SharedCounter.exe 1000000 4
1000000 increments over 4 threads
Counter value: 1000000

user at host:~/code/tests> mono SharedCounter.exe 1000000 8
1000000 increments over 8 threads
Counter value: 1000000

user at host:~/code/tests> mono SharedCounter.exe 1000000 16
1000000 increments over 16 threads
Counter value: 1000000

I shall try and figure out what the runtime is doing differently based on this
attribute (because presumably it is stored in the same place, presumably it is
using the same Monitor mechanisms, the only different is the enforcement of
single assignment semantics within the compiler).

Whilst this may fix the test program, other programs will still be broken if
there is any locking performed on mutable state.

-- 
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.


More information about the mono-bugs mailing list