2011-03-08 66 views
0

更新代碼的指針:11年3月7日:下午9時29分錯誤與通過使用線程

using namespace std; 

void * matrixACreate(void * param); 
void *status; 

struct a 
{ 
    int Arow; // Matrix A  
    int Acol; // WxX 
    int low; // Range low 
    int high; 
}; 

int main(int argc, char * argv[]) 
{  
    struct a matrix_mult_info; 

    matrix_mult_info.Arow = atoi(argv[1]); // Matrix A 
    matrix_mult_info.Acol = atoi(argv[2]); // WxX 

    matrix_mult_info.low = atoi(argv[5]); // Range low 
    matrix_mult_info.high = atoi(argv[6]); 

    pthread_t matrixAthread; 

    pthread_t runner; 
    int error, retValue; 

    struct a * a = (struct a *) malloc(sizeof(struct a)); 
    error = pthread_create(&matrixAthread, NULL, matrixACreate, a); 
    //error = pthread_create(&matrixAthread, NULL, matrixBCreate, sendB); 
    retValue = pthread_join(matrixAthread, &status); 
    //retValue = pthread_join(matrixBthread, &status); 

    return 0; 
} 

void * matrixACreate(void * param) {  
    struct a * matrix = (struct a *) param;  
    int range = ((matrix->high - matrix->low) + 1);  
    cout << matrix->Arow << endl;  
    return 0; 
}  
+0

請一些* *努力爲未來的問題設置代碼格式。它會幫助你理解問題,並幫助我們幫助你。 – 2011-03-08 02:40:32

+1

可能與http://stackoverflow.com/questions/5226033/multiplying-matrices-error-expected-primary-expression-before-struct以及多個用戶帳戶 – user470379 2011-03-08 02:42:36

+1

嚴重地,**關閉你的大寫鎖定鍵**時張貼評論。 – 2011-03-08 07:20:10

回答

5
struct a * a = (struct a *) malloc(sizeof(struct a)); 
// init a's members 
error = pthread_create(&matrixAthread, NULL, matrixACreate, a); 

編輯:在回答更新問題:

void * matrixACreate(void * param) { 
    struct a * matrix = (struct a *) param; 
    int range = ((matrix->high - matrix->low) + 1); 
    cout << matrix->Arow << endl; 
    return NULL; 
} 
+3

向我們展示完整的代碼,並定義「不起作用」的含義。崩潰?編譯器錯誤? – Erik 2011-03-08 01:20:23

+2

如果它不起作用,你要麼不告訴我們什麼,要麼你沒有遵循Erik的例子。 – 2011-03-08 01:20:44

+0

我會在哪裏把結構a *和NULL? – ohlegend 2011-03-08 02:09:32