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

Fix an issue causing lock contention in ObtainProxyType #60

Merged
merged 1 commit into from
Jun 25, 2014

Conversation

ksjoberg
Copy link

@ksjoberg ksjoberg commented Jun 4, 2014

It seems there is a misconception in how the ReaderWriterLockSlim works in regards to Upgradeable Read Locks.

MSDN: "Only one thread can enter upgradeable mode at any given time. If a thread is in upgradeable mode, and there are no threads waiting to enter write mode, any number of other threads can enter read mode, even if there are threads waiting to enter upgradeable mode."
-- http://msdn.microsoft.com/en-us/library/system.threading.readerwriterlockslim.enterupgradeablereadlock.aspx

This change avoids taking an upgradeable read lock for as long as possible, then serializes the execution (as the upgradeable read lock is acquired) but still lets other threads get read locks and potentially get cache hits while the new proxy type is generated. Only in the last moment (soon before the write to the cache) we upgrade to a write lock. This will drain the read locks and take the write lock, write the change to the cache and then release the lock. Other threads stuck on acquiring the read lock will continue, hitting the cache, and the threads waiting to acquire the upgradeable read lock will one by one get a cache hit or a cache miss followed by an upgrade and cache population.

kkozmic added a commit that referenced this pull request Jun 25, 2014
Fix an issue causing lock contention in ObtainProxyType
@kkozmic kkozmic merged commit 3491243 into castleproject:master Jun 25, 2014
@kkozmic
Copy link
Contributor

kkozmic commented Jun 25, 2014

@kenegozi I'll merge it and refactor that if needed

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.

3 participants