0
我得到這個公式的末尾的free()的,因爲錯誤段錯誤...分割故障多線程
不要我必須釋放臨時變量* STCK?或者因爲它是一個本地指針,並且 從來沒有通過malloc分配一個內存空間,編譯器會爲我清理它?
void * push(void * _stck)
{
stack * stck = (stack*)_stck;//temp stack
int task_per_thread = 0; //number of push per thread
pthread_mutex_lock(stck->mutex);
while(stck->head == MAX_STACK -1)
{
pthread_cond_wait(stck->has_space,stck->mutex);
}
while(task_per_thread <= (MAX_STACK/MAX_THREADS)&&
(stck->head < MAX_STACK) &&
(stck->item < MAX_STACK)//this is the amount of pushes
//we want to execute
)
{ //store actual value into stack
stck->list[stck->head]=stck->item+1;
stck->head = stck->head + 1;
stck->item = stck->item + 1;
task_per_thread = task_per_thread+1;
}
pthread_mutex_unlock(stck->mutex);
pthread_cond_signal(stck->has_element);
free(stck);
return NULL;
}
你是對的....我的自由搞亂了我的運行時間......但我仍然有其他問題....我仍然得到錯誤後刪除免費() – user852415 2012-01-29 16:42:19
@ user852415也回答了您的新問題..如果它對你有幫助,請標記爲已回答,並回答一個新問題,而不是再次更改。 – 2012-01-29 17:17:22