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