不管是linux也好,windows也好,学习就好!之前也用boost库尝试做了个线程池啥的,没做完,各种思考,毕竟真正接触的少!各种看资料,各种学习。过程中扎实好语言的基础,同时最重要的是,看着手册啥的来,比较能够学到东西,就是这样!
周末时间在看那个linux多线程服务端编程,说实话,比较不简单!只能是看点是点..还是太嫩了
-
// Thread.cpp : Defines the entry point for the console application.
-
//
-
-
#include "stdafx.h"
-
#include <windows.h>
-
-
DWORD WINAPI ThreadProc(LPVOID lpParameter);
-
-
int main(int argc, char* argv[])
-
{
-
int i = 0;
-
DWORD test = 0; ///< 0表示第一个子线程
-
HANDLE handle;
-
DWORD numThreadId = 0;
-
-
for (i = 0; i < 6; ++i)
-
{
-
///< 线程创建完毕后立即执行【由第5个参数决定】
-
handle = CreateThread(NULL, 0, ThreadProc, (LPVOID)&test, 0, &numThreadId);
-
if (handle)
-
{
-
Sleep(1000); ///< 为了让test每次是不同的值
-
test = numThreadId; ///< 表示"上一个"子线程线程ID
-
printf("thread %lld success start...\n", numThreadId);
-
CloseHandle(handle);
-
}
-
}
-
Sleep(1000);
-
-
return 0;
-
}
-
-
-
DWORD WINAPI ThreadProc(LPVOID lpParameter)
-
{
-
if (0 == *((DWORD *)lpParameter))
-
{
-
printf("currunt thread is run\n");
-
}
-
else
-
{
-
printf("forward threadID is %lld\n", *((DWORD *)lpParameter));
-
}
-
-
return 0;
-
}
-
-
/************************************************************************/
-
/* 运行结果
-
currunt thread is run
-
thread 2680 success start...
-
forward threadID is 2680
-
thread 3432 success start...
-
forward threadID is 3432
-
thread 3928 success start...
-
forward threadID is 3928
-
thread 1176 success start...
-
forward threadID is 1176
-
thread 2520 success start...
-
forward threadID is 2520
-
thread 3216 success start...
-
Press any key to continue */
-
/************************************************************************/
阅读(550) | 评论(0) | 转发(0) |