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

📄 dynamitethread.cpp

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

#include <windows.h>
#include <stdio.h>
#include "DynamiteThread.h"

// Dynamite thread's just light a fuse, burn down, and
// then explode by causing an exception to occur.
//
unsigned CDynamiteThread::GuardedThreadHandlerProc( void )
{
    printf(
        "[tid 0x%08lx] Dynamite thread running now - lighting fuse...",
        GetCurrentThreadId()
    );
    
    // Show the fuse burning down...
    //
    for( int i = 0; i < 5; i++ )
    {
        Sleep(1000);
        printf(".");
    }

    printf("!!!\n");

    // Boom!
    //
    *((PBYTE)0) = '!';

    // Will never reach this point.
    //
    printf(
        "[tid 0x%08lx] Dynamite thread exiting normally after explosion\n",
        GetCurrentThreadId()
    );

    return(0);
}

// The virtual exception filter handler is overridden just to display
// the sequence of events.
//
int CDynamiteThread::ExceptionFilter( DWORD dwExceptionCode, LPEXCEPTION_POINTERS pEP )
{
    printf(
        "[tid 0x%08lx] Dynamite exception filter running, exception = 0x%x\n",
        GetCurrentThreadId(),
        dwExceptionCode
    );

    return CGuardedThreadHandler::ExceptionFilter(dwExceptionCode, pEP);
}

// The virtual termination handler is overridden just to display
// the sequence of events.
//
unsigned CDynamiteThread::TerminationHandler( DWORD dwExceptionCode )
{
    printf(
        "[tid 0x%08lx] Dynamite termination handler running, exception = 0x%x\n",
        GetCurrentThreadId(),
        dwExceptionCode
    );

    return CGuardedThreadHandler::TerminationHandler(dwExceptionCode);
}

⌨️ 快捷键说明

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