-
Notifications
You must be signed in to change notification settings - Fork 0
Mutex
Pranav V R edited this page Jun 23, 2024
·
3 revisions
Mutex is the simplest type of synchronizer.Mutex is the short of Mutual Exclusion. Mutex is a synchronization mechanism used in concurrent programming to prevent multiple threads from simultaneously accessing a shared resource or critical section of code that cannot be executed concurrently. The primary purpose of a mutex is to ensure that only one thread at a time can perform a specific operation or access a shared resource, thereby preventing data races and ensuring thread safety.
- To avoid race condition
- They are often used for mutual exclusion, where only one thread can access a resource at a time.
- Using synchronized keyword (Provides intrinsic lock)
- Using ReentrantLock (Explicit locking)
- Using semaphore (setting permit count as 1)
- Java Concepts
- Multithreading
- Java 8 Features