线#
初始化线程类#
使用以下构造函数创建线程:
The thread
constructor creates a thread object with a callback function to be executed 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.
类方法#
get_id()#
The get_id()
method returns the ID of the tread.
**返回:**表示线程 ID 的整数。
join()#
The join()
method waits for the other thread to finish its execution.
**返回:**无。
detach()#
The detach()
method permits the thread to execute from the thread handle.
**返回:**无。
joinable()#
The joinable()
method returns if a thread is joinable.
**返回:**表示线程是否可连接的布尔值。
interrupt()#
The interrupt()
method stops the thread.
**返回:**无。
interruptAll()#
The interruptAll()
method stops all threads except main.
**返回:**无。
setPriority()#
The setPriority(priority)
method sets the priority of the thread as an integer.
范围 |
描述 |
---|---|
优先事项 |
表示线程优先级的整数。 |
**返回:**无。
priority()#
The priority()
method returns the priority of the thread as an integer.
**返回:**表示线程优先级的整数。
hardwareConcurrency()#
The hardwareConcurrency()
method returns the number of concurrent threads supported by the hardware.
**返回:**一个整数,表示硬件支持的并发线程数。