Skip to content

Commit 5ddd135

Browse files
committed
Tweaks
1 parent 14386cb commit 5ddd135

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

components/semaphore.rst

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ Installation
2424
Usage
2525
-----
2626

27-
Semaphore are used to guarantee exclusive access to some shared resource.
27+
In computer science, a semaphore is a variable or abstract data type used to
28+
control access to a common resource by multiple processes in a concurrent
29+
system such as a multitasking operating system. The main difference
30+
with :doc:`locks </lock>` is that semaphores allow more than one process to
31+
access a resource, whereas locks only allow one process.
2832

29-
Semaphore are created using a :class:`Symfony\\Component\\Semaphore\\SemaphoreFactory` class,
30-
which in turn requires another class to manage the storage of Semaphore::
33+
Create semaphores with the :class:`Symfony\\Component\\Semaphore\\SemaphoreFactory`
34+
class, which in turn requires another class to manage the storage::
3135

3236
use Symfony\Component\Semaphore\SemaphoreFactory;
3337
use Symfony\Component\Semaphore\Store\RedisStore;
@@ -38,13 +42,12 @@ which in turn requires another class to manage the storage of Semaphore::
3842
$store = new RedisStore($redis);
3943
$factory = new SemaphoreFactory($store);
4044

41-
4245
The semaphore is created by calling the
4346
:method:`Symfony\\Component\\Semaphore\\SemaphoreFactory::createSemaphore`
4447
method. Its first argument is an arbitrary string that represents the locked
45-
resource. Its second argument is the number of process allowed. Then, a call to
46-
the :method:`Symfony\\Component\\Semaphore\\SemaphoreInterface::acquire` method
47-
will try to acquire the semaphore::
48+
resource. Its second argument is the maximum number of process allowed. Then, a
49+
call to the :method:`Symfony\\Component\\Semaphore\\SemaphoreInterface::acquire`
50+
method will try to acquire the semaphore::
4851

4952
// ...
5053
$semaphore = $factory->createSemaphore('pdf-invoice-generation', 2);
@@ -62,7 +65,7 @@ already acquired.
6265

6366
.. note::
6467

65-
Unlike other implementations, the Semaphore Component distinguishes
68+
Unlike other implementations, the Semaphore component distinguishes
6669
semaphores instances even when they are created for the same resource. If a
6770
semaphore has to be used by several services, they should share the same
6871
``Semaphore`` instance returned by the ``SemaphoreFactory::createSemaphore``
@@ -73,7 +76,6 @@ already acquired.
7376
If you don't release the semaphore explicitly, it will be released
7477
automatically on instance destruction. In some cases, it can be useful to
7578
lock a resource across several requests. To disable the automatic release
76-
behavior, set the last argument of the ``createLock()`` method to
77-
``false``.
79+
behavior, set the fifth argument of the ``createLock()`` method to ``false``.
7880

7981
.. _`semaphores`: https://en.wikipedia.org/wiki/Semaphore_(programming)

0 commit comments

Comments
 (0)