[Mono-bugs] [Bug 70784][Nor] New - Problem with Threading.Interlocked.Increment

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 23 Dec 2004 16:34:43 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by fxjrlists@yahoo.com.br.

http://bugzilla.ximian.com/show_bug.cgi?id=70784

--- shadow/70784	2004-12-23 16:34:43.000000000 -0500
+++ shadow/70784.tmp.14040	2004-12-23 16:34:43.000000000 -0500
@@ -0,0 +1,123 @@
+Bug#: 70784
+Product: Mono: Runtime
+Version: 1.1
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: fxjrlists@yahoo.com.br               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Problem with Threading.Interlocked.Increment
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+
+I'm having problems with Threading.Interlocked.Increment.
+It seems to be being added twice.
+
+But after talking to kangaroo in irc and receiving a message from Kirk
+Marple, it turned out it seems a problem with string concatenation or
+nested function call.
+
+
+
+Steps to reproduce the problem:
+1. 
+
+This is the first version of testcase:
+
+public class t
+{
+    static Int32 i = 0;
+
+    public static void Main()
+    {
+
+        Console.WriteLine(System.Threading.Interlocked.Increment(ref i));
+        Console.WriteLine(System.Threading.Interlocked.Increment(ref i));
+        Console.WriteLine(System.Threading.Interlocked.Increment(ref i));
+        Console.WriteLine(System.Threading.Interlocked.Increment(ref i));
+
+
+
+    }
+
+}
+
+And result:
+
+0
+2
+4
+6
+
+After removing call to Interlocked.Increment inside Console.WriteLine it
+seemed to work.
+
+
+
+So I created this second test case:
+
+using System;
+
+public class t
+{
+    static Int32 i = 0;
+    
+    public static void Main()
+    {
+    
+        System.Threading.Interlocked.Increment(ref i);
+        
+        Console.WriteLine(i);
+        
+       
+        Console.WriteLine("a" + System.Threading.Interlocked.Increment(ref i));
+        d();
+        d();
+        
+        Console.WriteLine(d());
+        
+        
+        
+    }
+    
+    
+    
+    public static String d()
+    {
+        return "a" + System.Threading.Interlocked.Increment(ref i);
+        //System.Threading.Interlocked.Increment(ref i); return "a" + i;
+    }
+    
+}
+
+
+
+Where you get the following:
+
+1
+a2
+a8
+
+
+The first and second output is ok, but the third is somewhat strange.
+
+The commented line in method d() makes it works, again removing string
+concatenation.
+
+
+
+How often does this happen? 
+
+Always
+
+Additional Information: