⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 madmadworld.cpp

📁 window下的多线程编程参考书。值得一读
💻 CPP
字号:
//
// FILE: MadMadWorld.cpp
//
// Copyright (c) 1997 by Aaron Michael Cohen and Mike Woodring
//
/////////////////////////////////////////////////////////////////////////

#include <CMclGlobal.h>
#include <CMclThread.h>
#include <CMclEvent.h>
#include <CMclWaitableCollection.h>
#include <stdio.h>
#include "CWorkerThreadHandler.h"
#include "CMADThreadHandler.h"

void main( int iNumArgs )
{
    printf(
        "[0x%08lx] MadMadWorld starting up.\n",
        GetCurrentThreadId()
    );
    
    // Create the event that will be used to tell all our threads
    // (including the MAD thread) to exit normally.
    //
    CMclEvent               ExitEvent(TRUE, FALSE);

    // Create the MAD thread.
    //
    CMADThreadHandler       MADThreadHandler(ExitEvent);
    CMclThread              MADThread(&MADThreadHandler);

    // Create the first worker thread.
    //
    CWorkerThreadHandler    ThreadHandler1(ExitEvent, FALSE);
    CMclThread              Thread1(&ThreadHandler1);

    // Create the second worker thread (the one that might fault).
    //
    CWorkerThreadHandler    ThreadHandler2(ExitEvent, (iNumArgs > 1));
    CMclThread              Thread2(&ThreadHandler2);

    // Do some work for 10 seconds.
    //
    Sleep(10000);

    printf(
        "[0x%08lx] MadMadWorld notifying worker threads to exit.\n",
        GetCurrentThreadId()
    );

    // Tell the MAD and worker threads to exit.
    //
    ExitEvent.Set();

    // Wait for the threads to exit before terminating the process.
    //
    CMclWaitableCollection  AppThreads;

    AppThreads.AddObject(MADThread);
    AppThreads.AddObject(Thread1);
    AppThreads.AddObject(Thread2);

    AppThreads.Wait(TRUE, INFINITE);

    printf(
        "[0x%08lx] MadMadWorld exiting.\n",
        GetCurrentThreadId()
    );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -