天天看點

自定義腳本語言引擎開發紀實 - 多線程及線程同步

多線程及線程同步

    • 線程類 thread(c++實作)
    • 事件 event (c++實作)
    • 互斥量 Mutex (c++實作)

線程類 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++實作的内置類,腳本中可以直接執行個體化他們。

繼續閱讀