Thread¶
继承¶
Reference
简要描述¶
流程中的执行单位。
描述¶
流程中的执行单位。可以同时在Object上运行方法。如果使用共享对象,建议通过Mutex或Semaphore使用同步。
方法¶
| 返回值类型 | 方法名称 |
|---|---|
| String | get_id() const |
| bool | is_active() const |
| int | start(instance: Object, method: String, userdata: Variant = null, priority: int = 1) |
| Variant | wait_to_finish() |
| ##枚举 | |
| enum Priority: | |
| - PRIORITY_LOW = 0 |
以比正常情况低的优先级运行的线程。
- PRIORITY_NORMAL = 1
具有标准优先级的线程。
- PRIORITY_HIGH = 2
以比正常情况更高的优先级运行的线程。
方法说明¶
- get_id get_id() const
返回当前Thread的ID,在所有线程中唯一地标识它。
- is_active is_active() const
如果此Thread当前处于活动状态,则返回true。
- start start(instance: Object, method: String, userdata: Variant = null, priority: int = 1)
启动一个新的Thread,该线程在userdata作为参数传递的情况下,在对象instance上运行method。可以通过传递Priority枚举中的值来更改Thread的priority。
成功时,返回OK,失败时,返回ERR_CANT_CREATE。
- wait_to_finish wait_to_finish()
加入Thread并等待其完成。返回被调用的方法的返回值。