Shared Lock

Data System Architecture


A shared lock is a lock acquired in the shared mode over a data structure.

The data structure can be any:

A shared lock:

  • allows two or more process/thread to read from the data structure at the same time.
  • prevents another process from writing to the data structure while a process is reading it

Shared locks are usually used while the process is reading data (SQL SELECT operation , …)

A process/thread gets ownership of the data structure by obtaining the shared lock.

This is the first step step toward reading a file that can be accessed concurrently. For instance, a database application will acquire a shared lock on its database file before reading it.

Why ?

Without this lock, if a process is writing in the data structure (file, map, collection, …), a reading process might read:

  • some data before the change
  • and other data after the change.

The read would then not be consistent and the write change will then appear not atomic (even if it's).

In the context of a transaction, this read are called dirty read.

Discover More
Data System Architecture
Concurrency - Lock (Mutex)

A lock is a synchronizationmechanism designed to enforce a mutual exclusion of threads. A lock is also known as a mutex. Type: binary semaphore - yes / no Most locking designs block the execution...
Undraw File Manager Re Ms29
File - Read Operation

read is a file system io operations that opens the file for read access OS In the OS file system, it's equivalent to get a file descriptor. Linux API : read(2) Generally before reading a file,...

Share this page:
Follow us:
Task Runner