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 | 
|---|---|
| 
 | 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 integer 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 | 
|---|---|
| 
 | 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.
hardware_concurrency()#
The hardware_concurrency() method returns the number of concurrent threads supported by the hardware.
Returns: An integer representing the number of concurrent threads supported by the hardware.
swap()#
This method is called in the following ways:
The swap(x) method swaps the thread IDs with another specified thread.
| Parameters | Description | 
|---|---|
| 
 | The thread to swap to. | 
Returns: None.
The swap(x, y) method swaps two threads specified in the parameters.
| Parameters | Description | 
|---|---|
| 
 | A thread to swap with the next thread set in the parameter. | 
| 
 | A thread to swap with the previous thread set in the parameter. | 
Returns: None.