资源加载中... loading...

ThreadEvent

事件对象,用于多线程事件通知、信号。

set



set()

可以参考```threading.Event()```章节范例。


如果已经```set()```设置过,不能重复设置,需要清空之后重新设置信号。


{@fun/Threads/ThreadEvent/clear clear}, {@fun/Threads/ThreadEvent/wait wait}, {@fun/Threads/ThreadEvent/isSet isSet}

### clear

```clear()```函数用于清理信号。


clear()

可以参考```threading.Event()```章节范例。


{@fun/Threads/ThreadEvent/set set}, {@fun/Threads/ThreadEvent/wait wait}, {@fun/Threads/ThreadEvent/isSet isSet}

### wait

```wait()```函数用于设置事件(信号)等待,在事件(信号)被设置之前会阻塞;支持设置超时参数。


```wait()```函数返回是否超时,如果超时返回真值。

bool


wait()
wait(timeout)

参数```timeout```用于设置等待超时,单位毫秒。

timeout
false
number

```javascript
function main() {
    var event = threading.Event()
    var t1 = threading.Thread(function(event) {
        var ret = event.wait(100)
        Log(`event.wait(100):`, ret)
        ret = event.wait()
        Log(`event.wait():`, ret)
    }, event)

    Sleep(1000)
    event.set()
    t1.join()
}

测试wait()函数的返回值。

{@fun/Threads/ThreadEvent/set set}, {@fun/Threads/ThreadEvent/clear clear}, {@fun/Threads/ThreadEvent/isSet isSet}

isSet

isSet()函数用于判断是否已经设置了事件(信号)。

isSet()函数返回是否已经设置了事件(信号);如果当前已经设置过事件(信号)则返回真值。

bool

isSet()

可以参考threading.Event()章节范例。

{@fun/Threads/ThreadEvent/set set}, {@fun/Threads/ThreadEvent/clear clear}, {@fun/Threads/ThreadEvent/wait wait}

ThreadLock ThreadCondition