练习 多线程

#include "stdafx.h"
#include<iostream>
using namespace std;
#include <windows.h>

#include <stdio.h>  
#include <process.h>  


int a=1;
int b=1;


unsigned int __stdcall thread_fun1(void *param)
{   

    return 0;
}
DWORD WINAPI fun2(LPVOID lpParamter)
{
   a=a--;
   return NULL;
}
int main(int argc, char* argv[])
{
   

       HANDLE hThread =  (HANDLE)_beginthreadex(0,0,&thread_fun1,0,0,0); //thread 1
       WaitForSingleObject(hThread,INFINITE);
     
       HANDLE hThread2 = CreateThread(NULL, 0, fun2, NULL, 0, NULL);
       CloseHandle(hThread2);

        HANDLE hThread3 = CreateThread(NULL, 0, fun2, NULL, 0, NULL);
        CloseHandle(hThread3);
   
      cout<<a<<endl;
      cout<<GetCurrentThreadId()<<endl;

   return 0;
}
原文地址:https://www.cnblogs.com/ymecho/p/3348752.html