.. oe:namespace:: OEPlatform



.. meta::
   :keywords: OEThread, Thread


.. _OEPlatform_OEThread:

.. oe:class:: OEThread

   .. oe:api::


      class OEThread

   Abstracts away the notion of an operating system thread in a
   cross-platform way. Users can subclass this class and implement the
   :oe:meth:`OEPlatform::OEThread::Run` method in order to create new
   operating system threads running any arbitrary code. 

   .. oe:method:: Constructors

      .. oe:api::

         OEThread()

      Default constructor.

   .. oe:method:: operator=
      :language: c++

      .. oe:api::

         OEThread & operator=(const OEThread &)

      Assignment operator.


   

   .. oe:method:: GetArg

      .. oe:api::

         void* GetArg()

      Used by the implementation to pass the ``void *`` argument from
      :oe:meth:`OEPlatform::OEThread::Start` to the
      :oe:meth:`OEPlatform::OEThread::Run` method in a new thread. Not
      guaranteed to return anything useful on all platforms, and may
      go away in a future version.

   .. oe:method:: GetReturn

      .. oe:api::

         void* GetReturn()

      Used by the implementation to pass the ``void *`` returned from
      :oe:meth:`OEPlatform::OEThread::Run` to the
      :oe:meth:`OEPlatform::OEThread::Join` method in a new thread. Not
      guaranteed to return anything useful on all platforms, and may
      go away in a future version. If the thread is still running,
      this method can data race with the running thread, this should
      only be called after this thread is joined.


   .. oe:method:: GetStackSize

      .. oe:api::

         unsigned int GetStackSize() const

      Return the stack size chosen for this thread by a previous call
      to :oe:meth:`OEPlatform::OEThread::SetStackSize`. By default,
      this method will return ``0``, specifying that the operating
      system's default stack size will be used. 

   .. oe:method:: Join

      .. oe:api::

         void* Join()

      Blocks and wait for the thread to finish, returning the ``void *`` 
      returned by the overloaded :oe:meth:`OEPlatform::OEThread::Run` method. 

   .. oe:method:: Run

      .. oe:api::

         void* Run(void* targ)=0

      Pure virtual method expected to be overloaded by the inheriting
      class. This method will be started in a separate operating
      system thread after a successful call to
      :oe:meth:`OEPlatform::OEThread::Start`.

   .. oe:method:: SetArg

      .. oe:api::

         void SetArg(void* targ)

      Used by the implementation to pass the ``void *`` argument from
      :oe:meth:`OEPlatform::OEThread::Start` to the
      :oe:meth:`OEPlatform::OEThread::Run` method in a new thread. Not
      guaranteed to return anything useful on all platforms, and may
      go away in a future version.

   .. oe:method:: SetReturn

      .. oe:api::

         void SetReturn(void* targ)

      Used by the implementation to pass the ``void *`` returned from
      :oe:meth:`OEPlatform::OEThread::Run` to the
      :oe:meth:`OEPlatform::OEThread::Join` method in a new thread. Not
      guaranteed to return anything useful on all platforms, and may
      go away in a future version.


   .. oe:method:: SetStackSize

      .. oe:api::

         void SetStackSize(unsigned int stackSize)

      Specify the maximum size a stack can grow for this newly created
      operating system thread. This method must be called before
      calling :oe:meth:`OEPlatform::OEThread::Start`. Depending on the
      platform and the operating system settings,
      :oe:meth:`OEPlatform::OEThread::Start` may fail and return
      ``false`` if the value is considered inappropriate by the
      operating system. The value of ``0`` specifies to just use the
      operating system default. 


   .. oe:method:: Start

      .. oe:api::

         bool Start(void* targ = 0)

      Returns ``true`` if the operating system thread is successfully
      created, ``false`` otherwise.
