相关疑难解决方法(0)

在QueueUserAPC中指定的回调不会被调用

在我的代码中,我用它QueueUserAPC中断当前工作中的主线程,以便在回到之前的工作之前先调用一些回调.

std::string buffer;
std::tr1::shared_ptr<void> hMainThread;
VOID CALLBACK myCallback (ULONG_PTR dwParam) {
    FILE * f = fopen("somefile", "a");
    fprintf(f, "CALLBACK WAS INVOKED!\n");
    fclose(f);
}
void AdditionalThread () {
    // download some file using synchronous wininet and store the
    // HTTP response in buffer
    QueueUserAPC(myCallback, hMainThread.get(), (ULONG_PTR)0);
}
void storeHandle () {
    HANDLE hUnsafe;
    DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), 
        GetCurrentProcess(), &hUnsafe, 0, FALSE, DUPLICATE_SAME_ACCESS);
    hMainThread.reset(hUnsafe, CloseHandle);
}
void startSecondThread () {
    CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)AdditionalThread, 0, 0, NULL);
}
Run Code Online (Sandbox Code Playgroud)

storeHandlestartSecondThread …

c++ windows multithreading signals interrupt

4
推荐指数
1
解决办法
2507
查看次数

标签 统计

c++ ×1

interrupt ×1

multithreading ×1

signals ×1

windows ×1