thread#

Initializing the thread Class#

A Thread is created by using the following constructor:

The thread constructor creates a thread object with a callback function to be executed when the Thread is invoked.

Parameter

Description

callback

A previously defined function that will be executed as the entry point when the thread is invoked.

// Define the function "threadPrint".
void threadPrint(){
  brain.screen.print("Printing!");
}
int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Construct a thread "Thread" with the
  // thread class.
  thread Thread = thread(threadPrint);
}

This Thread object will be used in all subsequent examples throughout this API documentation when referring to thread class methods.

Class Methods#

get_id()#

The get_id() method returns the ID of the tread.

Returns: An interger that represents the thread’s ID.

join()#

The join() method waits for the other thread to finish its execution.

Returns: None.

detach()#

The detach() method permits the thread to execute from the thread handle.

Returns: None.

joinable()#

The joinable() method returns if a thread is joinable.

Returns: A boolean representing if a thread is joinable.

interrupt()#

The interrupt() method stops the thread.

Returns: None.

interruptAll()#

The interruptAll() method stops all threads except main.

Returns: None.

setPriority()#

The setPriority(priority) method sets the priority of the thread as an integer.

Parameter

Description

priority

An integer representing the priority of the thread.

Returns: None.

priority()#

The priority() method returns the priority of the thread as an integer.

Returns: An integer representing the priority of the thread.

hardwareConcurrency()#

The hardwareConcurrency() method returns the number of concurrent threads supported by the hardware.

Returns: An integer representing the number of concurrent threads supported by the hardware.