0

クラスでスレッドプールを処理しようとしています。以下は私のコードです。

#include <Windows.h>

class ClassA
{
public : // user API
    ClassA()
    {
    }

    ~ClassA()
    {
    }

public : //my muiti-thread func

    void init()
    {
        //*************************************
        // multithread Initialization
        //*************************************
        pool = NULL;
        cleanupgroup = NULL;
        rollback = 0;
        bool bRet = false;

        pool = CreateThreadpool(NULL);
        if(NULL == pool)
        {
            goto cleanPool;
        }
        rollback = 1;                                       

        SetThreadpoolThreadMaximum(pool, 5);                
        bRet = SetThreadpoolThreadMinimum(pool, 10);

        if (FALSE == bRet) {
            goto cleanPool;
        }

        cleanupgroup = CreateThreadpoolCleanupGroup();

        if (NULL == cleanupgroup) {
            goto cleanPool; 
        }

        rollback = 2;                                       

        SetThreadpoolCallbackPool(&CallBackEnviron, pool);

        SetThreadpoolCallbackCleanupGroup(&CallBackEnviron,
            cleanupgroup,
            NULL);

        return ;

cleanPool:
        switch (rollback) 
        {
        case 2:
            // Clean up the cleanup group.
            CloseThreadpoolCleanupGroup(cleanupgroup);

        case 1:
            // Clean up the pool.
            CloseThreadpool(pool);

        default:
            break;
        }

        return ;
    }

    void foo()
    {
        PTP_WORK work = NULL;
        work = CreateThreadpoolWork(ClassA::_delegate,
                        NULL, 
                        &CallBackEnviron);
    }

    static void __stdcall _delegate(PTP_CALLBACK_INSTANCE Instance, PVOID Parameter, PTP_WORK Work)
    {
        //some code
    }

    PTP_POOL pool;
    UINT rollback;
    TP_CALLBACK_ENVIRON CallBackEnviron;    
    PTP_CLEANUP_GROUP cleanupgroup;
};

int main()
{
    ClassA a;
    a.init();
    a.foo();
}

プロジェクトを作成してこのコードを実行すると、未処理の実行が発生します...理由はわかりません...

4

1 に答える 1