钢筋模板施工技术交底:C++ 多线程问题
来源:百度文库 编辑:中科新闻网 时间:2024/10/02 18:44:25
#define WIN32_LEAN_AND_MEAN included correctly
#include <windows.h>
#include <windowsx.h>
#include <conio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <math.h>
#include <io.h>
#include <fcntl.h>
// DEFINES ////////////////////////////////////////////////////////////////////////////////
// PROTOTYPES /////////////////////////////////////////////////////////////////////////////
DWORD WINAPI Printer_Thread(LPVOID data);
// GLOBALS ////////////////////////////////////////////////////////////////////////////////
// FUNCTIONS //////////////////////////////////////////////////////////////////////////////
DWORD WINAPI Printer_Thread(LPVOID data)
{
// this thread function simply prints out data 25 times with a slight delay
for (int index=0; index<25; index++)
{
printf("%d ",data);
Sleep(100);
}
return((DWORD)data);
} // end Printer_Thread
// MAIN //////////////////////////////////////////////////////////////////////////////////
void main(void)
{
HANDLE thread_handle;
DWORD thread_id;
printf("\nStarting threads...\n");
thread_handle = CreateThread(NULL,0,Printer_Thread,(LPVOID)1,0,&thread_id);
for (int index=0; index<50; index++)
{
printf("2 ");
Sleep(100);
}
CloseHandle(thread_handle);
printf("\nAll threads terminated.\n");
} // end main