Bugzilla – Bug 316603
[PATCH] InterlockedIncrement on (long) 2147483647 returns wrong value
Last modified: 2014-06-25 21:58:07 UTC
---- Reported by bmaurer@users.sf.net 2004-12-05 16:21:16 MST ---- [benm@omega benm]$ cat blah.cs using System; using System.Threading; class X { static void Main () { long l = 2147483647; long ll = l + 1; long res = Interlocked.Increment (ref l); Console.WriteLine ("Expected {0}", ll); Console.WriteLine ("In the operand {0}", l); Console.WriteLine ("Return value {0}", res); } } [benm@omega benm]$ mono blah.exe Expected 2147483648 In the operand 2147483648 Return value -2147483648 ---- Additional Comments From bmaurer@users.sf.net 2004-12-05 17:14:20 MST ---- Created an attachment (id=167112) patch ---- Additional Comments From bmaurer@users.sf.net 2004-12-05 17:17:35 MST ---- This fixes the bug. Note that the interlocked ops are not needed here. The implementation is not required to be (and is not on msft) thread safe when something other than Interlocked.{Increment, Decrement} is modifying the variable. So, the only writer to the variable inside that lock is the Interlocked method, which is protected by a mutex. ---- Additional Comments From lupus@ximian.com 2004-12-07 05:04:22 MST ---- Please commit (on the 1.0 branch, too). ---- Additional Comments From bmaurer@users.sf.net 2004-12-07 17:41:06 MST ---- Done Imported an attachment (id=167112) Unknown operating system unknown. Setting to default OS "Other".