- 最後登錄
- 2024-11-23
- 在線時間
- 7253 小時
- 註冊時間
- 2010-5-4
- 閱讀權限
- 95
- 精華
- 0
- UID
- 7964333
- 帖子
- 155
- 積分
- 1282 點
- 潛水值
- 47985 米
| 若有安裝色情守門員,可用無界、自由門等軟件瀏覽伊莉。或使用以下網址瀏覽伊莉: http://www.eyny.com:81/index.php 本帖最後由 tryit244178 於 2020-10-7 05:03 AM 編輯
參考參考- #include <iostream>
- #include <process.h>
- #include <windows.h>
- using namespace std;
- class Test{
- HANDLE hThread;
- unsigned threadID;
-
- public:
- int c = 0;
-
- Test(){}
-
- int cc()
- {
- return c;
- }
-
- void startThread()
- {
- hThread = (HANDLE)_beginthreadex(NULL, 0, &Test::BBB, this, 0, &threadID);
- }
-
- private:
- void AAA()
- {
- cout << "do something" << endl;
- c = 55;
- _endthreadex( 0 );
- }
-
- static unsigned int __stdcall BBB(void* p_this)
- {
- Test* p_Test = static_cast<Test*>(p_this);
- p_Test->AAA();
-
- WaitForSingleObject( p_Test->hThread, INFINITE );
- CloseHandle( p_Test->hThread );
- return 0;
- }
- };
-
- int main()
- {
- Test a, b;
- cout << a.cc() << "\t" << b.cc() << endl;
- b.c = 2;
- a.startThread();
- cout << a.cc() << "\t" << b.cc() << endl;
-
- return 0;
- }
複製代碼 ...
|
|