-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConcurrentDictionary from referencesources #139
Conversation
Reference source is deprecated |
I can try and get that version merged. I was testing the library today and got errors when casting ToArray(). I had used this ConcurrentDictionary in a .net 2.0 project without any concurrency issues. |
It means that there is a missing test in Theraot library. |
I can try, I have been maintaining https://github.com/Terricide/MonoLib this for several years. Today I tried to swap it out with this library and saw the issue deep within my code The version of MonoLib on github is old and I wanted to get all the additional dotnet backport stuff that I've done into this library I saw the item count inside the Dictionary go to -2 as well |
This sounds definitely as a bug. Just curious where do you need .NET 2.0? |
I just pushed my latest changes to that Mono repo But essentially I work on a systems management product and part of it is discovering computers on the network to manage and I want it to support the largest range of operating systems as possible and not require customers to have to install newer versions of .net on hundreds of machines. At some point I might make dotnet 4.0 the minimum or just switch to .net core, But even .net core doesn's support earlier versions of windows 10. Once we discover the devices we can patch it up as if the newer .net runtime if it is there. |
I also think it is cool that it should still run on windows 2000 if I ever needed it to :) |
It is cool but does it worth the effort ?:) Today even Windows 7 is not so common in enterprise. |
We have customers that purchased extended support from Microsoft and they are using our tool to patch windows 7 still. |
Windows 7 means .NET 3.5 at least. |
What were those errors? |
…t netstandard 1.0
I think dotnet 3.5 was still optional. |
The error I was getting was The array can not contain the number of elements |
Probably it is included by default but can be uninstalled. https://docs.microsoft.com/en-us/dotnet/framework/install/on-windows-7#net-framework-35 |
I wasnt sure what to do with Nullable parameter types it wouldn't compile for netstandard 1.0 |
{"@t":"2021-01-08T23:13:35.9955242Z","@mt":"TimeoutTasks:System.ArgumentException: The array can not contain the number of elements.\r\nParameter name: array\r\n at Theraot.Collections.ThreadSafe.Bucket |
@@ -27,7 +27,7 @@ | |||
<AssemblyVersion>3.2.1.0</AssemblyVersion> | |||
<FileVersion>3.2.1.0</FileVersion> | |||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | |||
<LangVersion>8.0</LangVersion> | |||
<LangVersion>9.0</LangVersion> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hereby claim that the fix in 605ed53 works. Problem being that Appveyor tests against .NET less than 4.0 are not working. That problem emerged with past sdk update. |
To explain how and why the problem happens: ToArray (and CopyTo) are the only two not atomic operations on the type. ToArray works by making an array of the appropriate size and then copying the values over. However, the number of items might increase after the array was initialized but before the copy completes. In which case the code would try to copy more elements that those that fit in the array, which is an exception. Edit: see the test introduced in 344e1b0 - it starts a few concurrent write tasks, then while those are running, it requests ToArray, only after ToArray completes the concurrent tasks are allowed to stop. This test failed with "The array can not contain the number of elements" in .NET 2.0. And didn't after the fix. To explain how and why the fix works: ToArray (and CopyTo) will require an exclusive lock on the dictionary. Also other write operations would also need some sort of lock to not happen concurrently with ToArray (and CopyTo). However, those other write operations have no problem happen concurrently. That means we need to kinds of locks: exclusive and not exclusive. That is what a read write lock does. So write operations take a read lock, and ToArray (and CopyTo) take a write lock. The read operations do not need a lock at all. |
I have succeeded porting ConcurrentDictionary from dotnet/runtime repository. |
I had already pushed a fix and a test for this: #139 (comment) |
The fix is on Nuget 3.2.2 |
No description provided.