heeman(abolfazl) Sadeghi on LinkedIn: Lock vs Monitor vs Semaphore vs Mutex vs SemaphoreSlim (2024)

heeman(abolfazl) Sadeghi

Senior BackEnd Developer|.Net|C#

  • Report this post

Lock vs Monitorvs Mutex vs Semaphorevs SemaphoreSlimin c#In this post I will explain about Lock, Monitor, Mutex, Semaphore , SemaphoreSlim1.Lock The lock statement acquires the mutual-exclusion lock for a given object, executes a statement block, and then releases the lock2.Monitorclass grants mutually exclusive access to a shared resource by acquiring or releasing a lock on the object that identifies the resource3.Semaphorewhich limits the number of threads that can access a shared resource or a pool of resources concurrently. The state of a semaphore is set to signaled when its count is greater than zero, and nonsignaled when its count is zero.4.Mutexwhich grants exclusive access to a shared resource. The state of a mutex is signaled if no thread owns it.5.SemaphoreSlimRepresents a lightweight alternative to Semaphore that limits the number of threads that can access a resource or pool of resources concurrently.In this post, I will briefly compare these items based on the following criteria1.Definition2.Single/Multi Threaded3.Method Enter and Exit4.Internal/External-process5.Resource Ownership6.NETFramework version that was introduced6.DeadLock

28

1 Comment

Like Comment

Shreekanta Kavaloor

Software Developer | Mentor | Ready to collaborate for open source

12h

  • Report this comment

Useful information. Thanks for sharing heeman(abolfazl) Sadeghi

Like Reply

1Reaction 2Reactions

To view or add a comment, sign in

More Relevant Posts

  • heeman(abolfazl) Sadeghi

    Senior BackEnd Developer|.Net|C#

    • Report this post

    TransactionInEF coreIn this post I will explain about TransactionInEF coreType of transactions1. Implicita)definition: You can use the SaveChanges.all changes in a single call to SaveChanges are applied in a transaction. b)default wayc)Commit/Rollback : Automatic,If any of the changes fail, then the transaction is rolled back and none of the changes are applied to the database.d) Simplicity2. Explicita)definition: You can use the DbContext.Database API to begin, commit, and rollback transactions.b)Commit/Rollback :Manualc) manage transaction in Dapper and raw SQL using this methodd) complex The following are discussed in the post1.Transaction dependencies2.Cross-context transaction3.IsolationLevela)ReadCommitted Shared locks are held while the data is being read to avoid dirty reads, but the data can be changed before the end of the transaction, resulting in non-repeatable reads or phantom data.b)ReadUncommitted A dirty read is possible, meaning that no shared locks are issued and no exclusive locks are honored.c)RepeatableRead Locks are placed on all data that is used in a query, preventing other users from updating the data. Prevents non-repeatable reads but phantom rows are still possible.d)Serializable A range lock is placed on the System.Data.DataSet,preventing other users from updating or inserting rows into the dataset until the transaction is complete.e)Snapshot Reduces blocking by storing a version of data that one application can read while another is modifying the same data. Indicates that from one transaction you cannot see changes made in other transactions, even if you requery.

    19

    To view or add a comment, sign in

  • heeman(abolfazl) Sadeghi

    Senior BackEnd Developer|.Net|C#

    • Report this post

    Service LifeTime in .net coreIn this post I will explain about Service LifeTime in .net core1.Singletoncreates an instance and shares it throughout the application.2.ScopedCreates only one instance per request and shares it in the request3.Transient·Creates a new instance every timeThe following are discussed in the post1.Definition every lifeTime2.Real UseCase3.suitable4.Sample output and graphic display5.Injecting one lifetime into another(dependencies)

    42

    Like Comment

    To view or add a comment, sign in

  • heeman(abolfazl) Sadeghi

    Senior BackEnd Developer|.Net|C#

    • Report this post

    File Manager in C# with FileTable sql serverManaging files in C# offers various methods, and one of them is using SQL Server's FileTable. This post will discuss the advantages and disadvantages of FileTable and with a sample code for a file management project.Get the latest source code here:https://lnkd.in/diuh4ihHFileTable The FileTable feature brings support for the Windows file namespace and compatibility with Windows applications to the file data stored in SQL Server.FileTable lets an application integrate its storage and data management components, and provides integrated SQL Server services - including full-text search and semantic search - over unstructured data and metadata.In other words, you can store files and documents in special tables in SQL Server called FileTables, but access them from Windows applications as if they were stored in the file system, without making any changes to your client applications.Advantages of Using FileTable in C#•Seamless Integration•Windows Compatibility•Transactional Support•A hierarchical namespace of directories and files•Support for Windows file and directory management APIs•Storage of file attributes, such as created date and modified dateDisadvantages of Using FileTable in C#•Complex Setup •Potential Overhead•Limited Framework Support(example, EF doesn't fully support it)

    15

    Like Comment

    To view or add a comment, sign in

  • heeman(abolfazl) Sadeghi

    Senior BackEnd Developer|.Net|C#

    • Report this post

    AOPinC#In this post, I will explain about AOP in C# with two examples AOPis a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns.It does so by adding behavior to existing code (an advice) without modifying the code, instead separately specifying which code is modified via a "pointcut" specification, such as "log all function calls when the function's name begins with 'set'". This allows behaviors that are not central to the business logic (such as logging) to be added to a program without cluttering the code of core functions.Cross-cutting concerns: are parts of a program that rely on or must affect many other parts of the system and are aspects of your application that are not part of the core functionality, but are required for the overall quality and reliability.uses ·Implementing logging in your application.·Monitoring and Caching·Using authentication before an operation·Implementing validation or notification for property setters ·Exception detection and handling and Event handling ·Changing the behavior of some methods.·Configuration and Localizationbenefits·It prevents violation of the DRY (don’t repeat yourself) principle·Stability/reliability and Improved extensibility·Reusability(developed once and applying it in places where need)·It makes it easier to follow the principle of single responsibilitySome implementation methods1.Code Weaving: Modifies code at compile time, often using tools like PostSharp.2.Interceptors: In this method, code is added at runtime using tools like reflection, and it is also known as dynamic proxy. Libraries such as Castle DynamicProxy are used to create dynamic proxies.3.Design Patterns(Decorator, Proxy, etc):Patterns like Decorator and Proxy add or control behavior without altering Main class structure.4.Framework Hooks: Some frameworks allow you to add code before and after a method execution#AOP #csharp

    22

    Like Comment

    To view or add a comment, sign in

  • heeman(abolfazl) Sadeghi

    Senior BackEnd Developer|.Net|C#

    • Report this post

    SpecificationPatterninC#Get the latest source code here:https://lnkd.in/d587WVPXIn this post, I will explain about Specification Pattern in C# with two examples (use with Expression linq and Specification IsSatisfiedBy)Specification Pattern:is a particular software design pattern, whereby business rules can be recombined by chaining the business rules together using bool logic.The pattern is frequently used in the context of domain-driven design.In this pattern, a unit of business logic inherits its functionality from the abstract aggregate Composite Specification classhelps to encapsulate a piece of domain knowledge into a single unit.The following are discussed in the post1. Definition2.Benefits3.Usage with Repository4.Implementing5.Popular packages(Ardalis.Specification)6.etc

    31

    Like Comment

    To view or add a comment, sign in

  • heeman(abolfazl) Sadeghi

    Senior BackEnd Developer|.Net|C#

    • Report this post

    Inheritance mapping strategy in EF coreIn this post, the inheritance mapping strategy in EF Core is explained through an example, along with a discussion of its advantages and disadvantagesGet the latest source code here:https://lnkd.in/d5dsjuwdEF supports 3 inheritance mapping strategy ·TPH (Table Per Hierarchy )·TPT (Table Per Type) ·TPC (Table Per Concrete Class) TPH (Table Per Hierarchy )· uses a single table to store the data for all types in the hierarchy·a discriminator column is used to identify which type each row represents.·This is the default method.·This table includes all propertiesin all hierarchiesTPT(Table-per-type)·all the types are mapped to individual tables(Includes base/parent and derived/child classes) ·Properties that belong solely to a base type or derived type are stored in a table that maps to that type. ·Tables that map to derived types also store a foreign key that joins the derived table with the base table.·PK of base table is created as PK and FK in child tables.TPC(Table-per-concrete-type)·each concrete type in the inheritance chain are mapped to individual tables but not the abstract class·Each table contains columns for all properties on the corresponding entity type. ·This addresses some common performance issues with the TPT strategy.·The TPC strategy is similar to the TPT strategy except that a different table is created for every concrete type in the hierarchy, but tables are not created for abstract types - hence the name “table-per-concrete-type”.#csharp #entityframework #entityframeworkCore

    36

    Like Comment

    To view or add a comment, sign in

  • heeman(abolfazl) Sadeghi

    Senior BackEnd Developer|.Net|C#

    • Report this post

    DRY andKISS andYAGNI with Example in C#In this Post, DRY andKISS andYAGNI is explained with an exampleSeveral examples were implemented in the project and an example is implemented in this postGet the latest source code here:https://lnkd.in/dKmDfSj6DRY "Don't repeat yourself"is a principle of software development aimed at reducing repetition of information which is likely to change, replacing it with abstractions that are less likely to change, or using data normalization which avoids redundancy in the first place.is stated as "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system".KISS - KEEP IT SIMPLE STUPIDthe KISS principle states that most systems work best if they are kept simple rather than made complicated; therefore, simplicity should be a key goal in design, and unnecessary complexity should be avoided.YAGNI "You aren't gonna need it"is a principle which arose from extreme programming (XP) that states a programmer should not add functionality until deemed necessary. Other forms of the phrase include "You aren't going to need it" (YAGTNI)and "You ain't gonna need it".

    36

    Like Comment

    To view or add a comment, sign in

  • heeman(abolfazl) Sadeghi

    Senior BackEnd Developer|.Net|C#

    • Report this post

    CROSS APPLY vs OUTER APPLY in SQL ServerIn this post, the difference between CROSS APPLY and OUTER APPLY in SQL Server is explained and some sample codes are displayed.APPLYThe APPLY operator allows you to invoke a table-valued function or table expression or table for each row returned by outer table expression of a query.CROSS APPLY ( similar inner join), returns only rows from the outer table that produce a result set from the table-valued function or table expression outerAPPLY ( similar Left join), returns both rows that produce a result set, and rows that do not, with NULL values in the columns produced by the table-valued function or table expression or table

    21

    Like Comment

    To view or add a comment, sign in

  • heeman(abolfazl) Sadeghi

    Senior BackEnd Developer|.Net|C#

    • Report this post

    In this post, I am going to talk about data structures in C#In C#, we have different types of datastructures, each of which has its own characteristics and uses.In this post, I'm going to introduce some of these structures and provide some highlights, comparisons, and examples about them.In this post, I will explain the following topics about data structures in C#:1. The important points about each data structure2. A brief comparison between different data structures based on these criteria: fixed size, thread safety, has key, iterator, generic/non-generic, update, get by index, hash data, allow null, unique elements, key/value, sort key, main method, etc.3. A comparison between different data structures using benchmarks4. A simple code example for each data structure5. The difference between multidimensional and jagged arraysIn this post, I will talk about the items below:Non-Concurrent Data Structures1.Array2.List3.Dictionary4.Hashtable5.Queue6.Stack7.SortedDictionary8.SortedList9.SortedSet10.LinkedList11. HashSetConcurrent Data Structures1.ConcurrentDictionary2.ConcurrentQueue3.ConcurrentStack4.ConcurrentBag5. BlockingCollectionYou can get the latest source code here:https://lnkd.in/dVhUPvFY#csharp

    33

    1 Comment

    Like Comment

    To view or add a comment, sign in

heeman(abolfazl) Sadeghi on LinkedIn: Lock vs Monitor vs Semaphore vs Mutex vs SemaphoreSlim (27)

heeman(abolfazl) Sadeghi on LinkedIn: Lock vs Monitor vs Semaphore vs Mutex vs SemaphoreSlim (28)

7,507 followers

  • 95 Posts

View Profile

Follow

Explore topics

  • Sales
  • Marketing
  • Business Administration
  • HR Management
  • Content Management
  • Engineering
  • Soft Skills
  • See All
heeman(abolfazl) Sadeghi on LinkedIn: Lock vs Monitor vs Semaphore vs Mutex vs SemaphoreSlim (2024)
Top Articles
Geico Commercial Actors 2024 Linda | Repeat Replay
Play Math Slither Online for Free | crazy games
Basketball Stars Unblocked 911
Houston Isd Applitrack
Citi Trends Watches
Ksat Doppler Radar
Bez.talanta Leaks
Weather On October 15
How To Pay My Big Lots Credit Card
Craigslist Southern Oregon Coast
Fatshark Forums
Generalausschreibung - The Race Days Stuttgart
Telegraph Ukraine podcast presenter David Knowles dies aged 32
Apple Store Location
Myzmanim Edison Nj
Westelm Order
Chicken Coop Brookhaven Ms
Claims Adjuster: Definition, Job Duties, How To Become One
Sandra Sancc
Bigbug Rotten Tomatoes
Ixl Spring Branch
Food King El Paso Ads
Craigslist Quad Cities
Irela Torres Only Fans
Syracuse Deadline
ASVAB Test: The Definitive Guide (updated 2024) by Mometrix
All Obituaries | Dante Jelks Funeral Home LLC. | Birmingham AL funeral home and cremation Gadsden AL funeral home and cremation
Tyrone's Unblocked Games Basketball
Gem City Surgeons Miami Valley South
Gander Mountain Mastercard Login
Slmd Skincare Appointment
Audarite
Case Overview: SAMA IM01 – SFF.Network
Free Stuff Craigslist Roanoke Va
Gym Membership & Workout Classes in Lafayette IN | VASA Fitness
Shs Games 1V1 Lol
Actionman23
Dr Roger Rosenstock Delray Beach
Donald Vacanti Obituary
O'reilly's Eastman Georgia
Re/Max Houses For Sale
Monte Carlo Poker Club Coin Pusher
Sallisaw Bin Store
Dermatologist Esthetician Jobs
Motorcycle Sale By Owner
Botw Royal Guard
Tillamook Headlight Herald Obituaries
Tia V15.1 Update
palm springs free stuff - craigslist
Synergy Grand Rapids Public Schools
Four Embarcadero Center - Lot #77
Jeff Buley Obituary
Latest Posts
Article information

Author: Foster Heidenreich CPA

Last Updated:

Views: 5716

Rating: 4.6 / 5 (76 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Foster Heidenreich CPA

Birthday: 1995-01-14

Address: 55021 Usha Garden, North Larisa, DE 19209

Phone: +6812240846623

Job: Corporate Healthcare Strategist

Hobby: Singing, Listening to music, Rafting, LARPing, Gardening, Quilting, Rappelling

Introduction: My name is Foster Heidenreich CPA, I am a delightful, quaint, glorious, quaint, faithful, enchanting, fine person who loves writing and wants to share my knowledge and understanding with you.