如何使用RMutex

2021-05-17 11:39:00 字數 1217 閱讀 6145

cs000969

s60 3rd edition, mr

使用rmutex可以確保你的執行緒不會再同一時間試圖改變同乙個值。rmutex.wait()提供乙個鎖機制,用rmutex.signal()才能開啟。

[hide

]

需要下列能力和鏈結庫

capability        none

library euser.lib

class cshared : cbase

;

生成乙個執行緒,並將cshared資料指標傳入:

// create shared data

ishareddata = cshared::newl();

// create threads

imythread = cmythread::newl(*this);

imythread->setshared(ishareddata);

imythread2 = cmythread::newl(*this);

imythread2->setshared(ishareddata);

執行緒呼叫rmutex::wait()開始睡眠等待

tint cmythread::threadfunction(tany* aparams)

在睡眠後呼叫periodictick()改變共享資料物件的值,並用rmutex::signal()釋放

tint cmythread::periodictick(tany* aobject)

// does not continue again

// note: does not work with this cperiodic class

return efalse;

}

完成cshared資料

cshared* cshared::newl()

cshared::cshared()

cshared::~cshared()

執行緒依次去改變共享物件的值,如果呼叫rmutex::wait()後另乙個執行緒就要等待,在rmutex::signal()之後才繼續。

如何使用 滅火器如何使用

滅火器的種類不同使用方法也不相同,下面單獨針對乾粉滅火器 泡沫滅火器和二氧化碳滅火器使用方法說明。一 乾粉滅火器的使用方法 適用範圍 適用於撲救各種易燃 可燃液體和易燃 可燃氣體火災,以及電器裝置火災。1 右手拖著壓把,左手拖著滅火器底部,輕輕取下滅火器。2 右手提著滅火器到現場。3 除掉鉛封。4 ...

如何使用 如何正確使用定速巡航

現在隨著造車技術的不斷創新和改進,越來越多的高科技功能都應用到了汽車上,不僅提供了實用性,也讓我們享受到了科技的快感。今天我們就聊一聊一項可以實現車輛自動駕駛的功能 定速巡航。定速巡航 cruise control system 簡稱ccs,簡單的理解就是給車子設定乙個速度值,駕駛員只需要掌握方向,...

如何使用CFileDialog

cfiledialog的語法 cfiledialog bool bopenfiledialog,lpctstr lpszdefext null,lpctstr lpszfilename null,dword dwflags ofn hidereadonly ofn overwriteprompt,l...