pthreads

    0熱度

    1回答

    我正在開發一個項目(而不是HOMEWORK),在C中構建一個多線程數獨解決方案驗證程序。我是C新手,所以請原諒我的代碼質量不好日臻完善。 我想從9個獨立的線程中調用方法row_check 9次。對於作爲參數的方法,我傳遞行號(arg)和數組名稱(arr)。我創建了線程,但我不確定如何正確地將參數傳遞給方法。誰能幫我這個? #include <pthread.h> #include <stdio.

    0熱度

    1回答

    我有一個循環調用pthread_join,但循環的順序與線程終止順序不匹配。 我如何監控線程完成,然後調用加入? for (int th=0; th<sections; th++) { cout<<"start joining "<<th<<endl<<flush; result_code = pthread_join(threads[th] , (void**)&statu

    0熱度

    1回答

    我在理解多線程有一些困難。這裏的情況: 我打算從一個數組中選擇一些整數,並將它們存儲到具有一些條件的另一個數組中。條件相當複雜,基本上它是array [i]和其他array [not i]之間的一個巨大的比較。我們稱之爲checkCondition(); 首先,我創建了pthread。這裏是我的代碼,注意dataPackage是一個包含數組的結構。 for(int i = 0; i < threa

    2熱度

    1回答

    我是Fortran和C++的新手,正在開發一個任務來連接兩個用Fortran和C++編寫的程序。 我想創建一個pthread(分離)包裝並從我的Fortran子例程中調用它並將cpp函數傳遞給它。我通過以下鏈接Calling a subroutine in FORTRAN without blocking the main program寫了一些代碼。 當我執行它時,出現如下所示的運行時錯誤。 P

    1熱度

    1回答

    在庫中pthread.h是pthread_rwlock_t FIFO? 在下面的例子中,我們有多個線程。想象一下,每個線程都保證按順序運行。 // Thread 1 - does a write lock pthread_rwlock_wrlock(&lock); // Thread 2 - does a read but has to wait for 1 pthread_rwlock_

    1熱度

    1回答

    我有以下的小的代碼片斷: int main() { pthread_t t = pthread_self(); std::cout << t << std::endl; return 0; } 當我編譯使用克++ 4.9.2 Linux的沒有任何庫+鏈路,輸出爲: 0 當我與並行線程如下鏈接: g++ test.c -o test -lpthread; .

    -1熱度

    1回答

    我想弄清楚我是否可以創建pthreads(或其他選擇),以便我的程序控制我係統中的所有線程。我不知道這是否有可能。任何幫助,將不勝感激!

    -1熱度

    2回答

    我正在嘗試使用多線程程序,並且pthread_join函數出現錯誤。從這段代碼的輸出是: after pthread_create Segmentation fault (core dumped) 這裏是代碼: #include <pthread.h> #include <stdio.h> #include <stdlib.h> void *myfunc1() { //

    1熱度

    1回答

    我正在使用pthread_cond_wait(),我仍然不確定它是如何工作的。我有更多的線程,做好這項工作: pthread_mutex_lock(&mutex); while(count() == 0){ pthread_cond_wait(&signal, &mutex); } //some critical section pthread_mutex_unlock

    0熱度

    1回答

    我在一個「工作人員」模式中使用pthreads,我有大量命令要運行,並且我想讀取每個命令的輸出併合並所有輸出。使用並行線程創建每個核心一個工作線程,每個工作線程基本上具有以下功能: for (;;) { const char *command = get_from_work_queue(); if (command == NULL) break; FILE