我有一個生產者/消費者併發問題,我正在處理。問題是我試圖創建第一個線程後立即引發了段錯誤。pthread創建後立即發生Segfault
相關代碼:
客戶是一個結構聲明:
struct pr2_customer
{
pthread_t customer_id;
};
typedef struct pr2_customer customer;
客戶是一個C++載體,聲明如下:
vector<customer> customers;
創建線程:
for(int i = 0; i < ncustomers; i++)
{
cout<<"creating a customer\n";
pthread_create(&customers[i].customer_id, &attr, customerAction, (void*)i);
}
輸出:
創建客戶
段錯誤
customerAction有一個COUT語句,它永遠也不會被執行的第一線,帶領我相信線程永遠不會創建。
任何幫助,非常感謝。
你可以發佈customerAction()的至少一部分嗎?你正在將一個整數轉換爲看起來不穩定的'void *'。 – mkb 2010-10-11 19:16:07