https://github.com/arnab-developer/lock-example
Example of lock with multiple thread with C#.
https://github.com/arnab-developer/lock-example
lock multithreading
Last synced: 3 months ago
JSON representation
Example of lock with multiple thread with C#.
- Host: GitHub
- URL: https://github.com/arnab-developer/lock-example
- Owner: Arnab-Developer
- License: mit
- Created: 2020-07-03T05:30:43.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-04-09T11:54:10.000Z (about 4 years ago)
- Last Synced: 2025-01-17T02:24:17.546Z (5 months ago)
- Topics: lock, multithreading
- Language: C#
- Homepage:
- Size: 37.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Use of `lock` in multithreading
This is a demo to show the use of `lock` in multithreading with C#.
There are two methods in class `LockExample.Lib.Utilities.SomeUtility`. One is with `lock` and another without.
```c#
public void PerformSomeOperationWithLock(InputOutputValue inputOutputValues)
{
lock (this)
{
// code here...
}
}public void PerformSomeOperationWithNoLock(InputOutputValue inputOutputValues)
{
// code here...
}
```There are two test cases are written for each of these in class `LockExample.Test.SomeUtilityTest` to show the operation difference.
```c#
[Fact]
public void PerformSomeOperationWithLockTest()
{
// code here...
}[Fact]
public void PerformSomeOperationWithNoLockTest()
{
// code here...
}
```