由单道批处理系统转化为多道批处理系统所存在问题的代码理解
// Demo.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "Demo.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// The one and only application object CWinApp theApp; using namespace std; static void sub(void *c);int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]){ int nRetCode = 0; /*//initialize MFC and print and error on failureif (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)){//TODO: change error code to suit your needscerr<< _T("Fatal Error: MFC initialization failed") << endl;nRetCode=1;}else{//TODO: code your application's behavior here.CString strHello;strHello.LoadString(IDS_HELLO);cout << (LPCTSTR)strHello << endl;}*/ char val='a'; char cb='A'; unsigned long v; HANDLE ha; ha=::CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)sub,&val,0,&v); ha=::CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)sub,&cb,0,&v); ::WaitForMultipleObjects(1,ha,true,INFINITE); return nRetCode;}static void sub(void *c) {char *p=(char *)c;char b;for(int i=0;i<26;i++){ //cout<<*p<<endl;b=*p+i;Sleep(88);//cout<<b<<endl; //cout<<(*p+i)<<endl; putchar(*p+i); }}
页:
[1]