我如何将值发送给线程而不是引用

时间:2015-04-21 09:07:32

标签: c pthreads

我在C中创建了一个线程,但它传递了引用而不是值。

  for (i=0; i<num_thread; i++){
  pthread_create(&thread[i], NULL, mou_oponent,(void *)&i);
}

int mou_oponent(void* ind) //THIS IS THE HEADER OF THE FUNCTION

我需要的值不是引用,因为我在线程中取i的值但是因为for的增加而改变它。

1 个答案:

答案 0 :(得分:0)

int mou_oponent(void* ind)中你应该通过其他变量复制到其他内存,然后你可以使用其他变量ind。 希望它有所帮助