线程的一些xxoo

#include "stdafx.h"
#include "windows.h"

DWORD WINAPI ThreadProc1(LPVOID lParam)
{
	int i=0;
	while(i++<10)
	{
		printf("fuck!\n");
	}
	return 0;
}

DWORD  WINAPI ThreadProc2(LPVOID lParam)
{
	int i=0;
	while(i++<10)
	{
		printf("shit!\n");
	}
	return 0;
}

int main(int argc,char *argv[])
{
	DWORD dwThreadId;              // 保存CreateThread传进来的线程ID

	HANDLE h[2];

	h[0]=CreateThread(NULL,NULL,ThreadProc1,NULL,CREATE_SUSPENDED,&dwThreadId);
	//让线程建立后先suspend起来

	SetThreadPriority(h[0],THREAD_PRIORITY_IDLE);      //空闲等级貌似比一般低好多

	ResumeThread(h[0]);           //这句不能让线程运行起来,只是唤醒被idle的进程

	h[1]=CreateThread(NULL,NULL,ThreadProc2,NULL,0,&dwThreadId);

	SetThreadPriority(h[1],THREAD_PRIORITY_NORMAL);     //一般等级的优先级
	WaitForMultipleObjects(2,h,TRUE,INFINITE);

	CloseHandle(h[1]);
	CloseHandle(h[0]);

	return 0;
}


代码写的很乱,权当记录而已

 

你可能感兴趣的:(windows,createthread)