Jump to content

Programming Reference:Thread Class: Difference between revisions

From BCI2000 Wiki
Mellinger (talk | contribs)
No edit summary
 
Mellinger (talk | contribs)
Line 6: Line 6:


==Methods==
==Methods==
===OSThread(bool createSuspended = false)===
===OSThread(bool createSuspended=false)===
The thread's constructor's argument determines whether thread execution is started immediately, or whether the thread is initially put into suspended state.
The thread's constructor's argument determines whether thread execution is started immediately, or whether the thread is initially put into suspended state. By default, the thread is created unsuspended.
 
===~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.

Revision as of 16:42, 8 September 2008

Location

BCI2000/src/shared/utils

Synopsis

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

Methods

OSThread(bool createSuspended=false)

The thread's constructor's argument determines whether thread execution is started immediately, or whether the thread is initially put into suspended state. By default, the thread is created unsuspended.

~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.

Suspend()

Puts the thread into suspended, i.e. halts execution.

Resume()

Resumes thread operation. For threads that have been created with the createSuspended argument set to true, Resume() will start thread execution.

Terminate()

Initiates thread termination by setting the Terminating property to true.

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

int ID (r)

The thread's OS thread id, or zero if the thread is not running.

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.