Bug 316603 (MONO70234) - [PATCH] InterlockedIncrement on (long) 2147483647 returns wrong value
Summary: [PATCH] InterlockedIncrement on (long) 2147483647 returns wrong value
Status: RESOLVED FIXED
Alias: MONO70234
Product: Mono: Runtime
Classification: Mono
Component: misc (show other bugs)
Version: 1.1
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Mono Bugs
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-05 23:21 UTC by Ben Maurer
Modified: 2014-06-25 21:58 UTC (History)
2 users (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
patch (1.40 KB, patch)
2004-12-06 00:14 UTC, Thomas Wiest
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 19:00:28 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".