Programming Reference:OSThread Class

From BCI2000 Wiki
Jump to navigation Jump to search




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



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


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.


Starts thread execution.


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.


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;


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