-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fixes #172 #175
base: main
Are you sure you want to change the base?
Fixes #172 #175
Conversation
I'm not sure if this is an actual fix, but it's difficult to recreate. This allows for multiple writers and readers, so there may be some instances where the highlighted cells are incorrect, but I'm not sure how that would happen. This also should only happen when rapidly visualizing bots, so shouldn't ever be noticeable anyway.
This probably will not fix the issue, but it is a small optimization. The [] operation does an Add anyways when the key is not present. |
Can you explain why this won't fix the issue? |
The original code and your code are doing the same thing under the hood.
Apparently multiple threads can alter the dictionary at the same time. Your code has lowered the probability of the exception, but the problem is still out there somewhere. |
Those aren't the same thing, though. The insertion behavior for |
True, that's why I said your code have lowered the probability, but it has not removed the main cause. |
It actually won't throw with multiple writers. You can wrap that line in a closure passed to I could be convinced that the correct way to do this is to use |
Parallel.For is too clever ;) It sometimes will not use multiple threads when the workload is done fast enough.
|
I'm not sure if that is an accurate recreation of the code, since the tasks are created and handled differently ( I'm still trying to recreate the error so I can test a fix, though, so if you have any suggestions on how to do that, let me know. :) |
My sample code was to show that My sample code is altering the dictionary in a tight loop, the actual code is doing, obviously, a lot more. We should investigate which code paths can be crossed simultaneously by the two threads to get an idea of what can be or should be guarded. |
I'm not sure if this is an actual fix, but it's difficult to recreate. This allows for multiple writers and readers, so there may be some instances where the highlighted cells are incorrect, but I'm not sure how that would happen. This also should only happen when rapidly visualizing bots, so shouldn't ever be noticeable anyway.