Table of Contents

Shared Lock

About

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

The data structure can be any:

A shared lock:

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:

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.