Jump to content

Programming Reference:Thread Class: Difference between revisions

From BCI2000 Wiki
Mellinger (talk | contribs)
Mellinger (talk | contribs)
Line 8: Line 8:
===OSThread()===
===OSThread()===
All threads are created in suspended state, and resumed by calling their ''Start()'' function.
All threads are created in suspended state, and resumed by calling their ''Start()'' function.
===~OSThread()===
===~OSThread()===
Deleting an <tt>OSThread</tt> object with a running thread associated will kill the thread, resulting in an undefined state of the parent process. Make sure that the <tt>IsTerminated</tt> property is ''true'' before deleting the <tt>OSThread</tt> object.
Deleting an <tt>OSThread</tt> object with a running thread associated will kill the thread, resulting in an undefined state of the parent process. Make sure that the <tt>IsTerminated</tt> property is ''true'' before deleting the <tt>OSThread</tt> object.
Line 15: Line 14:
===Terminate()===
===Terminate()===
Initiates thread termination by setting the <tt>Terminating</tt> property to ''true''.
Initiates thread termination by setting the <tt>Terminating</tt> property to ''true''.
==Static Methods==
===Sleep( int ms )===
Puts the thread to sleep for the amount of time specified in ms.


==Events==
==Events==

Revision as of 16:11, 19 January 2011

Location

BCI2000/src/shared/utils

Synopsis

The OSThread class provides a wrapper for OS-dependent thread functionality.

Methods

OSThread()

All threads are created in suspended state, and resumed by calling their Start() function.

~OSThread()

Deleting an OSThread object with a running thread associated will kill the thread, resulting in an undefined state of the parent process. Make sure that the IsTerminated property is true before deleting the OSThread object.

Start()

Starts thread execution.

Terminate()

Initiates thread termination by setting the Terminating property to true.

Static Methods

Sleep( int ms )

Puts the thread to sleep for the amount of time specified in ms.

Events

int Execute

This is the thread's main function. Typically, it will consist of a processing loop that exits when the thread's IsTerminating property becomes true:

int MyThread::Execute()
{
  while( !IsTerminating() )
  { // do something
    ...
  }
  return 0;
}

Properties

bool IsTerminating (r)

True after Terminate() has been called on the thread.

bool IsTerminated (r)

True after the thread has been terminated.

int Result (r)

The return code of the thread's Execute() function on termination of the thread.