stdthread

    3熱度

    1回答

    是否可以從std::packaged_task創建std::future,它在單獨的線程上執行,但並不總是檢索其結果? #include <future> #include <thread> class Result { Result() {} ~Result() {} }; void foo() { std::packaged_task<Result()

    0熱度

    1回答

    我對std :: thread很新,我很快意識到創建它們至少在運行W7的計算機上是相當昂貴的。 所以我決定創建我的線程和使用樣例代碼爲作業發送到它:http://en.cppreference.com/w/cpp/thread/condition_variable 我的代碼運行良好,沒有崩潰,但是我沒有看到太多的性能提升,所以我測量的時間的工作之間的差異完成和主線程完成檢測工作的時間(請參閱Wai

    2熱度

    2回答

    我在C++中擁有以下代碼。該代碼是從C++ Concurrency In Action: Practical Multithreading void do_work(unsigned id); void f() { std::vector<std::thread> threads; for(unsigned i = 0; i < 20; ++i) { threa

    0熱度

    2回答

    所以我決定今天給C++一個試試。我下載了MinGw和它附帶的g ++編譯器。我決定測試下面的代碼: #include <iostream> #include <thread> int foo() { std::cout << "foo" << std::endl; } int main() { std::thread t1(foo); t1.join(

    0熱度

    1回答

    我一直在試用std:thread。我爲標準算術運算使用二進制表達式樹。我正在創建一個線程來執行計算,並希望檢查除以零。當線程啓動std::async時,異常從工作線程拋出並在主線程中捕獲得很好。當我用std :: thread啓動線程時,拋出異常時,出現運行時錯誤abort()。任何見解爲什麼它與std::async but not std :: thread`? // Declaration i

    0熱度

    1回答

    我想通過一個指向線程的功能,但它給回主 for (int i = 0; i < threadCount; ++i) { ptrTabThreads = new std::thread(checkMin, ptrTab[i]); ptrTabThreads->join(); ++ptrTabThreads; } error: attempt to use a de

    1熱度

    1回答

    我遇到了一點奇怪的行爲,當我嘗試編譯使用多線程在CodeLite任何程序。 我得到的錯誤: terminate called after throwing an instance of 'std::system_error' what(): Enable multithreading to use std::thread: Operation not premitted. 一些快速g

    1熱度

    1回答

    我想在單獨的線程中啓動std :: function類型。 我的代碼目前看起來是這樣的: struct bar { std::function<void(int,int)> var; }; struct foo { bar* b; foo() { std::thread t(b->var); //Error attempt to us

    0熱度

    1回答

    MPI使用多個進程運行我的程序。 我想讓這些進程之一休眠一段時間,以便使用最少的CPU。 std::this_thread::sleep_for()看起來像我想要的,但thread位在這種情況下看起來有點粗略。 可以這樣做嗎?

    3熱度

    2回答

    我創建了一個new std :: thread對象,然後detach()它。線程運行一段任意時間,然後自行終止。由於我使用new創建了該對象,因此我需要delete才能釋放其資源?或者線程有效delete本身終止? 如果確實有效delete本身,如果我明確delete它終止後會發生什麼壞事?