簡體   English   中英

通過TBB庫創建線程

[英]Creating a thread in via TBB library

我有這樣的代碼:

    #include <iostream>
    #include <tbb/tbb.h>
    #include <Windows.h>



    bool MyThread(int something)
    {
        std::cout << "This is a thread function\n" << std::endl;

        for (int i = 0; i < 10000; i++)
        {
            something++;
            Sleep(1);
        }

        return true;
    }

    int main ()
    {
        tbb::tbb_thread pMyThread = tbb::tbb_thread(MyThread, 3);

        pMyThread.join();

        return 0;
    }

但是,如果我在VS 2008中對其進行編譯,則會顯示:錯誤C2248:'tbb :: internal :: tbb_thread_v3 :: tbb_thread_v3':無法訪問在類'tbb :: internal :: tbb_thread_v3'中聲明的私有成員

用於main()函數的第一個字符串。 我哪里錯了?

這很可能在不應該調用副本構造函數的情況下,請嘗試以下方法:

tbb::tbb_thread myThread(MyThread, 3); 

如果可以的話,還應該考慮使用標頭中的std :: thread

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM