mirror of
https://github.com/godotengine/godot-docs-l10n.git
synced 2025-12-31 09:49:22 +03:00
110 lines
4.7 KiB
ReStructuredText
110 lines
4.7 KiB
ReStructuredText
:github_url: hide
|
||
|
||
.. _class_Mutex:
|
||
|
||
Mutex
|
||
=====
|
||
|
||
**Hérite de :** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
|
||
|
||
Un :ref:`Semaphore<class_Semaphore>` binaire pour la synchronisation de plusieurs :ref:`Thread<class_Thread>`\ s.
|
||
|
||
.. rst-class:: classref-introduction-group
|
||
|
||
Description
|
||
-----------
|
||
|
||
A synchronization mutex (mutual exclusion). This is used to synchronize multiple :ref:`Thread<class_Thread>`\ s, and is equivalent to a binary :ref:`Semaphore<class_Semaphore>`. It guarantees that only one thread can access a critical section at a time.
|
||
|
||
This is a reentrant mutex, meaning that it can be locked multiple times by one thread, provided it also unlocks it as many times.
|
||
|
||
\ **Warning:** To ensure proper cleanup without crashes or deadlocks, the following conditions must be met:
|
||
|
||
- When a **Mutex**'s reference count reaches zero and it is therefore destroyed, no threads (including the one on which the destruction will happen) must have it locked.
|
||
|
||
- When a :ref:`Thread<class_Thread>`'s reference count reaches zero and it is therefore destroyed, it must not have any mutex locked.
|
||
|
||
.. rst-class:: classref-introduction-group
|
||
|
||
Tutoriels
|
||
------------------
|
||
|
||
- :doc:`Utiliser plusieurs fils d'exécution <../tutorials/performance/using_multiple_threads>`
|
||
|
||
- :doc:`Les API sûres pour plusieurs fils d'exécution <../tutorials/performance/thread_safe_apis>`
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
Méthodes
|
||
----------------
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+-------------------------+----------------------------------------------------+
|
||
| |void| | :ref:`lock<class_Mutex_method_lock>`\ (\ ) |
|
||
+-------------------------+----------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`try_lock<class_Mutex_method_try_lock>`\ (\ ) |
|
||
+-------------------------+----------------------------------------------------+
|
||
| |void| | :ref:`unlock<class_Mutex_method_unlock>`\ (\ ) |
|
||
+-------------------------+----------------------------------------------------+
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
Descriptions des méthodes
|
||
--------------------------------------------------
|
||
|
||
.. _class_Mutex_method_lock:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **lock**\ (\ ) :ref:`🔗<class_Mutex_method_lock>`
|
||
|
||
Verrouille ce **Mutex**, le bloque jusqu'à ce qu'il soit déverrouillé par le propriétaire actuel.
|
||
|
||
\ **Note :** Cette fonction renvoie sans bloquer si ce thread est déjà le propriétaire du mutex.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Mutex_method_try_lock:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **try_lock**\ (\ ) :ref:`🔗<class_Mutex_method_try_lock>`
|
||
|
||
Essaie de verrouiller ce **Mutex**, mais ne le bloque pas. Renvoie ``true`` en cas de succès, ``false`` sinon.
|
||
|
||
\ **Note :** Cette fonction renvoie ``true`` si le thread possède déjà le mutex.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Mutex_method_unlock:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **unlock**\ (\ ) :ref:`🔗<class_Mutex_method_unlock>`
|
||
|
||
Unlocks this **Mutex**, leaving it to other threads.
|
||
|
||
\ **Note:** If a thread called :ref:`lock()<class_Mutex_method_lock>` or :ref:`try_lock()<class_Mutex_method_try_lock>` multiple times while already having ownership of the mutex, it must also call :ref:`unlock()<class_Mutex_method_unlock>` the same number of times in order to unlock it correctly.
|
||
|
||
\ **Warning:** Calling :ref:`unlock()<class_Mutex_method_unlock>` more times than :ref:`lock()<class_Mutex_method_lock>` on a given thread, thus ending up trying to unlock a non-locked mutex, is wrong and may causes crashes or deadlocks.
|
||
|
||
.. |virtual| replace:: :abbr:`virtual (Cette méthode doit typiquement être redéfinie par l'utilisateur pour avoir un effet.)`
|
||
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
|
||
.. |const| replace:: :abbr:`const (Cette méthode n'a pas d'effets de bord. Elle ne modifie aucune des variables membres de l'instance.)`
|
||
.. |vararg| replace:: :abbr:`vararg (Cette méthode accepte n'importe quel nombre d'arguments après ceux décris ici.)`
|
||
.. |constructor| replace:: :abbr:`constructor (Cette méthode est utilisée pour construire un type.)`
|
||
.. |static| replace:: :abbr:`static (Cette méthode n'a pas besoin d'instance pour être appelée, elle peut donc être directement appelée en utilisant le nom de la classe.)`
|
||
.. |operator| replace:: :abbr:`operator (Cette méthode décrit un opérateur valide à utiliser avec ce type en tant qu'opérande gauche.)`
|
||
.. |bitfield| replace:: :abbr:`BitField (Cette valeur est un nombre entier composé d'un masque de bits des options suivantes.)`
|
||
.. |void| replace:: :abbr:`void (Aucune valeur de retour.)`
|