Skip to content

Commit a533c35

Browse files
committed
Tweaks and rewords
1 parent f45dba1 commit a533c35

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

components/lock.rst

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -168,34 +168,37 @@ object) and ``isExpired()`` (which returns a boolean).
168168
Shared Locks
169169
------------
170170

171-
Sometimes, a data structure cannot be updated atomically and is invalid during
172-
the time of the update. In this situation, other process should not read or
173-
write the data until the update is complete. But once updated, multiple process
174-
can read the data in parallel.
171+
.. versionadded:: 5.2
172+
173+
Shared locks (and the associated ``acquireRead()`` method and
174+
``SharedLockStoreInterface``) were introduced in Symfony 5.2.
175175

176-
In this situation, a common solution is to use shared lock which allows
177-
concurent access for read-only operations, while write operations require
178-
exclusive access.
176+
A shared or `readers–writer lock`_ is a synchronization primitive that allows
177+
concurrent access for read-only operations, while write operations require
178+
exclusive access. This means that multiple threads can read the data in parallel
179+
but an exclusive lock is needed for writing or modifying data. They are used for
180+
example for data structures that cannot be updated atomically and are invalid
181+
until the update is complete.
179182

180183
Use the :method:`Symfony\\Component\\Lock\\LockInterface::acquireRead` method
181184
to acquire a read-only lock, and the existing
182185
:method:`Symfony\\Component\\Lock\\LockInterface::acquire` method to acquire a
183-
write lock.::
186+
write lock::
184187

185188
$lock = $factory->createLock('user'.$user->id);
186189
if (!$lock->acquireRead()) {
187190
return;
188191
}
189192

190-
Similare to the ``acquire`` method, pass ``true`` as the argument of the ``acquireRead()``
191-
method to acquire the lock in a blocking mode.::
193+
Similar to the ``acquire()`` method, pass ``true`` as the argument of ``acquireRead()``
194+
to acquire the lock in a blocking mode::
192195

193196
$lock = $factory->createLock('user'.$user->id);
194197
$lock->acquireRead(true);
195198

196-
When a read-only lock is acquired with the method ``acquireRead``, it's
197-
possible to **Promote** the lock, and change it to write lock, by calling the
198-
``acquire`` method.::
199+
When a read-only lock is acquired with the method ``acquireRead()``, it's
200+
possible to **promote** the lock, and change it to write lock, by calling the
201+
``acquire()`` method::
199202

200203
$lock = $factory->createLock('user'.$userId);
201204
$lock->acquireRead(true);
@@ -207,13 +210,8 @@ possible to **Promote** the lock, and change it to write lock, by calling the
207210
$lock->acquire(true); // Promote the lock to write lock
208211
$this->update($userId);
209212

210-
In the same way, it's possible to **Demote** a write lock, and change it to a
211-
read-only lock by calling the ``acquireRead`` method.
212-
213-
.. versionadded:: 5.2
214-
215-
The ``Lock::acquireRead`` method and ``SharedLockStoreInterface`` interface
216-
and were introduced in Symfony 5.2.
213+
In the same way, it's possible to **demote** a write lock, and change it to a
214+
read-only lock by calling the ``acquireRead()`` method.
217215

218216
The Owner of The Lock
219217
---------------------
@@ -833,3 +831,4 @@ are still running.
833831
.. _`PHP semaphore functions`: https://www.php.net/manual/en/book.sem.php
834832
.. _`Replica Set Read and Write Semantics`: https://docs.mongodb.com/manual/applications/replication/
835833
.. _`ZooKeeper`: https://zookeeper.apache.org/
834+
.. _`readers–writer lock`: https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock

0 commit comments

Comments
 (0)