Jump to content

Programming Reference:Thread Class: Difference between revisions

From BCI2000 Wiki
Mellinger (talk | contribs)
Mellinger (talk | contribs)
No edit summary
(4 intermediate revisions by the same user not shown)
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.
===Start()===
===Start()===
Starts thread execution.
Starts thread execution.
===Terminate()===
===Terminate([OSEvent*])===
Initiates thread termination by setting the <tt>Terminating</tt> property to ''true''.
Initiates thread termination by setting the <tt>Terminating</tt> property to ''true''. When a pointer to an [[Programming Reference::OSEvent Class|<tt>OSEvent</tt>]] object is specified as an argument, the  [[Programming Reference::OSEvent Class|<tt>OSEvent</tt>]] object will be set to signaled state as soon as thread execution has terminated.
 
==Static Methods==
===Sleep( int ms )===
Puts the current thread to sleep for the amount of time specified in ms.


==Events==
==Events==
Line 30: Line 33:
</pre>
</pre>
==Properties==
==Properties==
===int ID (r)===
The thread's OS thread id, or zero if the thread is not running.
===bool IsTerminating (r)===
===bool IsTerminating (r)===
True after <tt>Terminate()</tt> has been called on the thread.
True after <tt>Terminate()</tt> has been called on the thread.
Line 38: Line 39:
===int Result (r)===
===int Result (r)===
The return code of the thread's <tt>Execute()</tt> function on termination of the thread.
The return code of the thread's <tt>Execute()</tt> function on termination of the thread.
[[Programming Reference:OSEvent Class]], [[Programming Reference:OSMutex Class]]


[[Category:Framework API]][[Category:Development]]
[[Category:Framework API]][[Category:Development]]

Revision as of 14:49, 2 May 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([OSEvent*])

Initiates thread termination by setting the Terminating property to true. When a pointer to an OSEvent object is specified as an argument, the OSEvent object will be set to signaled state as soon as thread execution has terminated.

Static Methods

Sleep( int ms )

Puts the current 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.

Programming Reference:OSEvent Class, Programming Reference:OSMutex Class