Skip to content

Create and manage locks dynamically in run-time in concurrent software

License

Notifications You must be signed in to change notification settings

saeedmaghdam/DynaLock

Repository files navigation

DynaLock

Create and manage locks dynamically in run-time in concurrent software

DynaLock is a library to create and manage locks dynamically in run-time in concurrent software, DynaLock hides all concurrency complexities in distributed systems. DynaLock currently supports Monitor, Semaphore, SemaphoreSlim, AutoResetEvent and ManualResetEvent.

Important

DynaLock is currecntly under development and only supports Monitor, Semaphore, SemaphoreSlim, AutoResetEvent and ManualResetEvent.

In a very near future, new features will be added to DynaLock

Please contribute in development!

Features

  • DynaLock's Monitor

    • Create and manage locker objects dynamically in run-time
  • DynaLock's Semaphore

    • Create and manage semaphore objects dynamically in run-time
  • DynaLock's SemaphoreSlim

    • Create and manage semaphore slim objects dynamically in run-time
  • DynaLock's AutoResetEvent

    • Create and manage auto reset event objects dynamically in run-time
  • DynaLock's ManualResetEvent

    • Create and manage manual reset event objects dynamically in run-time
  • DynaLock's Context

    • Create specific work space for different domains to avoid CPU and resource wasting, improve performance, etc.
    • Both DynaLock's Monitor and DynaLock's Semaphore could be injected a context using builder class.
  • DynaLock's Meta-Data

    • An object that be used to store some info like string values, integers, instances of spesific classes and data structures, so meta-data could be accesses from different threads in current domain.
    • Both DynaLock's Monitor and DynaLock's Semaphore could be injected a meta-data object using property.

Installation

To install DynaLock in Visual Studio's Package Manager Console:

Install-Package DynaLock -Version 2.5.1

To install in a specific project use:

Install-Package DynaLock -Version 2.5.1 -ProjectName Your_Project_Name

To update package use:

Update-Package DynaLock

To update package in a specific project use:

Update-Package DynaLock -ProjectName Your_Project_Name

Or visit DynaLock's Nuget page to get more information.

Usage example

DynaLock is easy to use.

using (var monitor = new DynaLock.MonitorBuilder()
	.Name("enter_a_unique_name")
	.Build()
){
	...
	monitor.TryEnter();
	...
	if (monitor.IsLockOwned){
		// Some code
	} else {
		// Some code
	}
	...
}

And if you've more domain and would like to have individual context per domain, you could use DynaLock like:

DynaLock.Context.Monitor domain1_context  =  new  DynaLock.Context.Monitor()
DynaLock.Context.Monitor domain2_context  =  new  DynaLock.Context.Monitor()

using (var monitor = new DynaLock.MonitorBuilder()
	.Context(domain1_context)
	.Name("enter_a_unique_name_in_current_domain")
	.Build()
){
	...
	monitor.TryEnter();
	...
	if (monitor.IsLockOwned){
		// Some code
	} else {
		// Some code
	}
	...
}



using (var monitor = new DynaLock.MonitorBuilder()
	.Context(domain2_context)
	.Name("enter_a_unique_name_in_current_domain")
	.Build()
){
	...
	monitor.TryEnter();
	...
	if (monitor.IsLockOwned){
		// Some code
	} else {
		// Some code
	}
	...
}

In the above senario, all resources are completely seperated per context and CPU(s) will not be wasted anymore.

Also, you could find working examples in DynaLock.Test project.

Release History

Visit CHANGELOG.md to see full change log history of DynaLock

  • 2.5.0
    • Added SemaphoreSlim to DynaLock
  • 2.4.0
    • Added flag to DynaLock to give more power to developers
  • 2.3.0
    • Added ManualResetEvent to DynaLock
  • 2.2.0
    • Added AutoResetEvent to DynaLock
  • 2.0.0
    • Added meta-data to contexts
    • Refactored and improved the source code
    • Added comments to methods, properties and classes
  • 1.1.0
    • Added Semaphore to DynaLock
  • 1.0.0
    • Initialized DynaLock

Meta

Saeed Aghdam – Linkedin

Distributed under the MIT license. See LICENSE for more information.

https://github.com/saeedmaghdam/

Contributing

  1. Fork it (https://github.com/saeedmaghdam/DynaLock/fork)

  2. Create your feature branch (git checkout -b feature/your-branch-name)

  3. Commit your changes (git commit -am 'Add a short message describes new feature')

  4. Push to the branch (git push origin feature/your-branch-name)

  5. Create a new Pull Request