VC 多執行緒程式設計入門示例

2021-08-01 21:21:33 字數 544 閱讀 7201

程式分析:建立乙個子執行緒,當主線程開始執行的時候,子執行緒同時開始執行,由於資源有限(如本程式中的螢幕列印),子執行緒和主線程執行速度不同,因此會隨機交替執行。如果希望子執行緒和主線程有序的交替執行的話,可以加乙個互斥鎖

// threadtest.cpp : 定義控制台應用程式的入口點。

//#include "stdafx.h"

#include #include using namespace std;

handle hmutex = null;//互斥量

dword winapi fun(lpvoid lpparamter)

return 0l;

}int main()

return 0;

}

執行結果:

vc 多執行緒程式設計

mfc2.afxbeginthread函式建立和初始化cwinthread物件,啟動並返回位址。3.pthread new cwinthread pthread m bautodelete false pthread afxbeginthread startandclosethreadproc,nu...

vc 多執行緒程式設計

vc 中的多執行緒程式設計 createamutexwithnoinitialowner.必須要建立乙個控制代碼 hmutex createmutex null,nosecurityattributes false,initiallynotowned mutextoprotectdatabase n...

vc 多執行緒程式設計 SOCKET通訊

vc 多執行緒程式設計 socket通訊 include stdafx.h include 伺服器端程式 dword winapi answerthread lpvoid lparam int main sockaddr in service service.sin family af inet s...