Skip to content
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

Resolved 2 issues with multi threaded code for issue #57 #61

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Resolved 2 issues with multi threaded code for issue #57 #61

wants to merge 2 commits into from

Conversation

RubberChickenParadise
Copy link

  1. Fixed identified issue in SqlQueryProvider.cs UpdateItems where using DateTime.Now.Ticks could cause duplicate table names if calls to update happened fast enough for the same main table.

Fixed by switching to GUID

  1. Fixed race condition in MappingHelper.cs EfMappingFactory where 2 threads could evaluate if (!cache.TryGetValue(type, out mapping)) before either one had added the context type to the internal cache.

Fixed by adding a lock around the code to add the item to the cache dictionary to prevent 2 threads trying to add the same item.

…e name if the command is executed fast enough.
If 2 threads reached if (!cache.TryGetValue(type, out mapping)) before an item was added to the cache both threads would then try to add the item to the cache causing the second to fail.
By adding a lock and a second TryGetValue we can prevent this by allowing the first thread to successfully add the item to cache then release the lock.
When the second thread is no longer blocked it will do a TryGetValue and retrieve the value from cache.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant