Bug 7414 - System.Collections.Concurrent.ConcurrentDictionary is broken
Summary: System.Collections.Concurrent.ConcurrentDictionary is broken
Status: RESOLVED NORESPONSE
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Jérémie Laval
URL:
Depends on:
Blocks:
 
Reported: 2012-09-24 08:15 UTC by richard
Modified: 2012-11-15 10:37 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NORESPONSE

Description richard 2012-09-24 08:15:29 UTC
Description of Problem:

ConcurrentDictionary.AddOrUpdate is missbehaving. Seems ok with one thread, but with multiple it is not.
See below for unit test (nunit).


Steps to reproduce the problem: (see unit test)

using NUnit.Framework;
using NUnit.Framework.Constraints;

namespace Threading
{
	class Dictionary
	{
		[Test]
		public void a ()
		{
			var threads = new List<Task> ();
			var d = new ConcurrentDictionary<string,int> ();
			
			for (var i=0; i<10; i++) {
				threads.Add (
					Task.Factory.StartNew (() => {
					for (var j=0; j<10000; j++) {
						d.AddOrUpdate ("one", 1, (key,oldValue) => oldValue + 1);
					}
				}));
			}
			
			Task.WaitAll (threads.ToArray ());
			System.Threading.Thread.Sleep (10000); //wait some more.
			
			Assert.That (d.Count, Is.EqualTo (1));
			Assert.That (d ["one"], Is.EqualTo (100000)); //this one fails
		}
	}
}


Actual Results:
varies always less that 100000

Expected Results:
10000

How often does this happen? 
More that half the time.

Additional Information:
MonoDevelop 2.8.6.3
Installation UUID: 2775fbaf-eaa7-4f1e-bdf7-f5f1ee71874a
Runtime:
	Mono 2.10.8.1 (Debian 2.10.8.1-1ubuntu2.2)
	GTK 2.24.10
	GTK# (2.12.0.0)
Build information:
	Git revision: f4289daf57621f5593ad5bf78b3ff5ad878e3c7a-dirty
	Build date: 2012-02-20 07:20:06+0000
Operating System:
	Linux
	Linux ubuntu-VirtualBox 3.2.0-30-generic-pae #48-Ubuntu SMP Fri Aug 24 17:14:09 UTC 2012 i686 i686 i386 GNU/Linux
Loaded assemblies:
MonoDevelop.RegexToolkit             2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.RegexToolkit/MonoDevelop.RegexToolkit.dll
nunit.core.interfaces                2.5.10.0       /usr/lib/mono/gac/nunit.core.interfaces/2.5.10.0__96d09a1eb7f44a77/nunit.core.interfaces.dll
mdhost                               1.0.0.0        /usr/lib/monodevelop/bin/mdhost.exe
System.Runtime.Remoting              4.0.0.0        /usr/lib/mono/gac/System.Runtime.Remoting/4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
MonoDevelop.Debugger.Soft.AspNet     0.0.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.Debugger.Soft/MonoDevelop.Debugger.Soft.AspNet.dll
MonoDevelop.Debugger.Soft            2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.Debugger.Soft/MonoDevelop.Debugger.Soft.dll
Mono.Debugger.Soft                   0.0.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft.dll
Mono.Debugging.Soft                  0.0.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft.dll
MonoDevelop.AspNet.Mvc               2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.AspNet.Mvc/MonoDevelop.AspNet.Mvc.dll
MonoDevelop.CodeMetrics              2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.CodeMetrics/MonoDevelop.CodeMetrics.dll
MonoDevelop.WebReferences            2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.WebReferences/MonoDevelop.WebReferences.dll
MonoDevelop.DocFood                  1.0.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.DocFood.dll
gconf-sharp                          2.24.0.0       /usr/lib/mono/gac/gconf-sharp/2.24.0.0__35e10195dab3c99f/gconf-sharp.dll
NUnitRunner                          0.0.0.0        /usr/lib/monodevelop/AddIns/NUnit/NUnitRunner.dll
MonoDevelop.CBinding                 2.6.0.0        /usr/lib/monodevelop/AddIns/BackendBindings/MonoDevelop.CBinding.dll
ILAsmBinding                         2.6.0.0        /usr/lib/monodevelop/AddIns/BackendBindings/ILAsmBinding.dll
OldNRefactory                        2.1.1.0        /usr/lib/monodevelop/bin/OldNRefactory.dll
MonoDevelop.HexEditor                2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.HexEditor.dll
MonoDevelop.AssemblyBrowser          2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.AssemblyBrowser.dll
MonoDevelop.AspNet                   2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.AspNet/MonoDevelop.AspNet.dll
ICSharpCode.NRefactory               1.0.4433.13142 /usr/lib/monodevelop/bin/ICSharpCode.NRefactory.dll
MonoDevelop.XmlEditor                2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.XmlEditor/MonoDevelop.XmlEditor.dll
MonoDevelop.TextTemplating           2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.TextTemplating/MonoDevelop.TextTemplating.dll
Mono.TextTemplating                  0.0.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.TextTemplating/Mono.TextTemplating.dll
MonoDevelop.Gettext                  2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.Gettext/MonoDevelop.Gettext.dll
MonoDevelop.Projects.Formats.MSBuild 1.0.0.0        /usr/lib/monodevelop/bin/MonoDevelop.Projects.Formats.MSBuild.exe
MonoDevelop.Autotools                2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.Autotools/MonoDevelop.Autotools.dll
I18N.Rare                            4.0.0.0        /usr/lib/mono/gac/I18N.Rare/4.0.0.0__0738eb9f132ed756/I18N.Rare.dll
I18N.CJK                             4.0.0.0        /usr/lib/mono/gac/I18N.CJK/4.0.0.0__0738eb9f132ed756/I18N.CJK.dll
I18N.MidEast                         4.0.0.0        /usr/lib/mono/gac/I18N.MidEast/4.0.0.0__0738eb9f132ed756/I18N.MidEast.dll
I18N.Other                           4.0.0.0        /usr/lib/mono/gac/I18N.Other/4.0.0.0__0738eb9f132ed756/I18N.Other.dll
I18N.West                            4.0.0.0        /usr/lib/mono/gac/I18N.West/4.0.0.0__0738eb9f132ed756/I18N.West.dll
I18N                                 4.0.0.0        /usr/lib/mono/gac/I18N/4.0.0.0__0738eb9f132ed756/I18N.dll
ICSharpCode.SharpZipLib              2.84.0.0       /usr/lib/mono/gac/ICSharpCode.SharpZipLib/2.84.0.0__1b03e6acf1164f73/ICSharpCode.SharpZipLib.dll
Mono.Security                        4.0.0.0        /usr/lib/mono/gac/Mono.Security/4.0.0.0__0738eb9f132ed756/Mono.Security.dll
MonoDevelop.GtkCore                  2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.GtkCore/MonoDevelop.GtkCore.dll
libsteticui                          0.0.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.GtkCore/libsteticui.dll
libstetic                            0.0.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.GtkCore/libstetic.dll
MonoDevelop.Deployment.Linux         2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.Deployment/MonoDevelop.Deployment.Linux.dll
MonoDevelop.Deployment               2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.Deployment/MonoDevelop.Deployment.dll
MonoDevelop.MsVisualStudio           2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.MsVisualStudio/MonoDevelop.MsVisualStudio.dll
MonoDevelop.VBNetBinding             2.6.0.0        /usr/lib/monodevelop/AddIns/BackendBindings/MonoDevelop.VBNetBinding.dll
MonoDevelop.CSharpBinding            2.6.0.0        /usr/lib/monodevelop/AddIns/BackendBindings/MonoDevelop.CSharpBinding.dll
MonoDevelop.Refactoring              2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.Refactoring/MonoDevelop.Refactoring.dll
MonoDevelop.SourceEditor2            2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.SourceEditor2.dll
MonoDevelop.NUnit                    2.6.0.0        /usr/lib/monodevelop/AddIns/NUnit/MonoDevelop.NUnit.dll
MonoDevelop.DesignerSupport          2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.dll
Mono.Debugging                       0.0.0.0        /usr/lib/monodevelop/bin/Mono.Debugging.dll
MonoDevelop.Debugger                 2.6.0.0        /usr/lib/monodevelop/AddIns/MonoDevelop.Debugger/MonoDevelop.Debugger.dll
pango-sharp                          2.12.0.0       /usr/lib/mono/gac/pango-sharp/2.12.0.0__35e10195dab3c99f/pango-sharp.dll
monodoc                              1.0.0.0        /usr/lib/mono/gac/monodoc/1.0.0.0__0738eb9f132ed756/monodoc.dll
System.Drawing                       4.0.0.0        /usr/lib/mono/gac/System.Drawing/4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
Mono.Cecil                           0.9.4.0        /usr/lib/monodevelop/bin/Mono.Cecil.dll
gnome-vfs-sharp                      2.24.0.0       /usr/lib/mono/gac/gnome-vfs-sharp/2.24.0.0__35e10195dab3c99f/gnome-vfs-sharp.dll
gnome-sharp                          2.24.0.0       /usr/lib/mono/gac/gnome-sharp/2.24.0.0__35e10195dab3c99f/gnome-sharp.dll
GnomePlatform                        2.6.0.0        /usr/lib/monodevelop/AddIns/GnomePlatform/GnomePlatform.dll
System.Configuration                 4.0.0.0        /usr/lib/mono/gac/System.Configuration/4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
Mono.Cairo                           4.0.0.0        /usr/lib/mono/gac/Mono.Cairo/4.0.0.0__0738eb9f132ed756/Mono.Cairo.dll
gdk-sharp                            2.12.0.0       /usr/lib/mono/gac/gdk-sharp/2.12.0.0__35e10195dab3c99f/gdk-sharp.dll
Mono.TextEditor                      1.0.0.0        /usr/lib/monodevelop/bin/Mono.TextEditor.dll
atk-sharp                            2.12.0.0       /usr/lib/mono/gac/atk-sharp/2.12.0.0__35e10195dab3c99f/atk-sharp.dll
glib-sharp                           2.12.0.0       /usr/lib/mono/gac/glib-sharp/2.12.0.0__35e10195dab3c99f/glib-sharp.dll
gtk-sharp                            2.12.0.0       /usr/lib/mono/gac/gtk-sharp/2.12.0.0__35e10195dab3c99f/gtk-sharp.dll
Mono.Posix                           4.0.0.0        /usr/lib/mono/gac/Mono.Posix/4.0.0.0__0738eb9f132ed756/Mono.Posix.dll
Mono.Addins                          0.6.0.0        /usr/lib/mono/gac/Mono.Addins/0.6.0.0__0738eb9f132ed756/Mono.Addins.dll
Mono.Addins.Setup                    0.6.0.0        /usr/lib/mono/gac/Mono.Addins.Setup/0.6.0.0__0738eb9f132ed756/Mono.Addins.Setup.dll
System.Xml                           4.0.0.0        /usr/lib/mono/gac/System.Xml/4.0.0.0__b77a5c561934e089/System.Xml.dll
System.Xml.Linq                      4.0.0.0        /usr/lib/mono/gac/System.Xml.Linq/4.0.0.0__b77a5c561934e089/System.Xml.Linq.dll
System.Core                          4.0.0.0        /usr/lib/mono/gac/System.Core/4.0.0.0__b77a5c561934e089/System.Core.dll
System                               4.0.0.0        /usr/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll
MonoDevelop.Core                     2.6.0.0        /usr/lib/monodevelop/bin/MonoDevelop.Core.dll
MonoDevelop.Ide                      2.6.0.0        /usr/lib/monodevelop/bin/MonoDevelop.Ide.dll
MonoDevelop                          2.6.0.0        /usr/lib/monodevelop/bin/MonoDevelop.exe
mscorlib                             4.0.0.0        /usr/lib/mono/4.0/mscorlib.dll
Comment 1 Jérémie Laval 2012-09-27 07:16:29 UTC
Hey,

Thanks for the reporting. I cannot reproduce the problem on mono master, could you try it on your side to make sure the problem was fixed?

Thanks
Comment 2 Jérémie Laval 2012-11-15 10:37:34 UTC
I will close this bug as it's working on master for me. Don't hesitate to reopen if you still see the issue with a recent mono.