I just discovered that every request in an ASP.Net web application gets a Session lock at the beginning of a request, and then releases it at the end of the request!
I prepared a library based on links posted in this thread. It uses the examples from MSDN and CodeProject. Thanks to James.
I also made modifications advised by Joel Mueller.
Code is here:
https://github.com/dermeister0/LockFreeSessionState
HashTable module:
Install-Package Heavysoft.LockFreeSessionState.HashTable
ScaleOut StateServer module:
Install-Package Heavysoft.LockFreeSessionState.Soss
Custom module:
Install-Package Heavysoft.LockFreeSessionState.Common
If you want to implement support of Memcached or Redis, install this package. Then inherit the LockFreeSessionStateModule class and implement abstract methods.
The code is not tested on production yet. Also need to improve error handling. Exceptions are not caught in current implementation.
Some lock-free session providers using Redis: