多线程

#include <Windows.h>
#include <stdlib.h>

DWORD WINAPI mymsg(LPVOID lp)
{
    MessageBoxA(0, "hello", "China", 0);
    return 0;
}

void main()
{
    HANDLE hthread;
    DWORD threadid;//保存线程编号

    for (int i = 0; i < 5; i++)
    {
        hthread = CreateThread(
            NULL,//安全属性
            NULL,//堆栈大小
            mymsg,//线程的入口点
            NULL,//函数的参数
            0,//立即执行
            &threadid);//保存线程的id
        
        WaitForSingleObject(hthread, INFINITE);//一个一个执行
    }

    system("pause");
}

 

posted @ 2016-01-04 14:39  喵小喵~  阅读(122)  评论(0)    收藏  举报