自定义脚本语言引擎开发纪实 - 多线程及线程同步

线程类 thread(c++实现)

_thread = thread($G:__callback__,$G:__engine__,"_thread")
_thread.ext="text"
_thread.sum=10
//开启的线程执行mm.script中的逻辑
_thread.start("C:\\Users\\Administrator\\Desktop\\pack_236\\mm.script")
//等待10秒(单位:ms)
_thread.wait(10000)

事件 event (c++实现)

//线程1

e=event()
e.create(1,0,"Local\\eventtest")
e.nosignal()
//do somthing
e.signal()

//线程2

e=event()
e.open("Local\\eventtest")
ret=e.wait(-1)

互斥量 Mutex (c++实现)

//线程1

m=mutex()
m.create(0,"Local\\mutextest")
//do somthing
ret=m.wait(-1)

//线程2

m=mutex()
m.open("Local\\mutextest")
m.release()

这三个内置的和线程有关的类,是用C++实现的内置类,脚本中可以直接实例化他们。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章