C thread 執行緒封裝類

2021-09-11 18:14:25 字數 1052 閱讀 5592

思路是這樣的,寫乙個thread抽象類,有函式virtual void run()=0,類中呼叫window api函式createthread()建立並啟動執行緒,所有執行緒都執行同乙個靜態函式threadfunction(lpvoid param),param傳遞執行緒物件的this指標

createthread(null, 0, thread::wthreadfunctionlinek, (lpvoid)this, 0, &nthreadid);

在threadfunction函式中將param強轉為thread型別,利用多型特性呼叫run()函式,run的具體實現由子類完成。

dword __stdcall thread::wthreadfunctionlinek(lpvoid param)

#pragma once

#include

class thread;

typedef

void

(*wthreadfunction)

(thread* pobj)

;//執行緒類;

class thread

;

#include

"thread.h"

thread:

:thread()

void thread:

:start()

}void thread:

:stop()

void thread:

:waitexit()

dword __stdcall thread:

:wthreadfunctionlinek

(lpvoid param)

//繼承wthread;

class example: public wthread}}

;wint32 _tmain

(wint32 argc, _tchar* ar**)

C Thread 執行緒狀態知識

net 基礎類庫的system.threading命名空間提供了大量的類和介面支援多執行緒。這個命名空間有很多的類。system.threading.thread類是建立並控制線程,設定其優先順序並獲取其狀態最為常用的類。他有很多的方法,在這裡我們將就比較常用和重要的方法做一下介紹 thread.s...

c Thread 執行緒狀態知識

thread函式 函式名執行進入的狀態及其他說明 thread.start 啟動執行緒的執行 thread.suspend 掛起執行緒,或者如果執行緒已掛起,則不起作用 thread.resume 繼續已掛起的執行緒 thread.interrupt 中止處於 wait或者sleep或者join 執...

C Thread 執行緒狀態知識

net 基礎類庫的system.threading命名空間提供了大量的類和介面支援多執行緒。這個命名空間有很多的類。system.threading.thread類是建立並控制線程,設定其優先順序並獲取其狀態最為常用的類。他有很多的方法,在這裡我們將就比較常用和重要的方法做一下介紹 thread.s...