.. oe:namespace:: OEPlatform


.. meta::
   :keywords: OETryMutex, TryMutex


.. _OEPlatform_OETryMutex:

.. oe:class:: OETryMutex

   .. oe:api::

      class OETryMutex

   This class represents `OETryMutex`.

   The :ref:`OETryMutex <OEPlatform_OETryMutex>` class provides a portable
   MUTual EXclusion device, that is useful for protecting shared data
   structures from concurrent modification. This version also contains
   :oe:meth:`OEPlatform::OETryMutex::Try` method that allows for a
   failed acquire. :ref:`OETryMutex <OEPlatform_OETryMutex>` is slightly more
   costly than :ref:`OEMutex <OEPlatform_OEMutex>`.

   .. oe:method:: Constructors

      .. oe:api::

         OETryMutex()

      Default constructor.

   .. oe:method:: Acquire

      .. oe:api::

         void Acquire()

      Acquires (locks) the :ref:`OETryMutex <OEPlatform_OETryMutex>`. If the
      :ref:`OETryMutex <OEPlatform_OETryMutex>` is unlocked, it is locked by
      this calls and becomes owned by the calling thread. If the
      :ref:`OETryMutex <OEPlatform_OETryMutex>` is already locked, by this or
      another thread, :oe:meth:`OEPlatform::OETryMutex::Acquire`
      suspends the calling thread until the
      :ref:`OETryMutex <OEPlatform_OETryMutex>` is released.

   .. oe:method:: Release

      .. oe:api::

         void Release()

      Releases (unlocks) the :ref:`OETryMutex <OEPlatform_OETryMutex>`. The
      :ref:`OETryMutex <OEPlatform_OETryMutex>` object must have previously been
      locked by the calling thread.

   .. oe:method:: Try

      .. oe:api::

         bool Try()

      Attempts to acquire (lock) the
      :ref:`OETryMutex <OEPlatform_OETryMutex>`. If the
      :ref:`OETryMutex <OEPlatform_OETryMutex>` is unlocked, it is locked by
      this call, becomes owned by the calling thread, and returns
      ``true``. If the :ref:`OETryMutex <OEPlatform_OETryMutex>` is already locked,
      by this or another thread, :oe:meth:`OEPlatform::OETryMutex::Try`
      returns ``false``.
