【发布时间】:2015-04-20 03:01:03
【问题描述】:
void * consumer_child(void *arguments){
Range rng = *((Range *) arguments);
//prinnting with the range to easily identify each thread
printf("consumer_child[%d-%d] started\n", rng.start, rng.end );
pthread_exit(0);
}
当我打印它时,它会打印内存位置,而不是值。我需要打印值。
在主线程中正确设置了开始和结束值。我已经检查过了。
在main中我将参数设置如下
Range *rng = malloc(sizeof(*rng));
rng->start = i * numbersPerChild;
rng->end = (numbersPerChild * (i + 1)) -1 ;
printf("Range for thread %d is %d to %d\n", i, rng->start, rng->end );
printf("test print %d\n",rng->start);
pthread_create(&tid[i], NULL, consumer_child, (void *)&rng );
范围是一个结构
typedef struct
{
int start;
int end;
} Range;
【问题讨论】:
-
什么是范围?你是如何创建线程的?
-
将
(void *)&rng更改为rng。 -
@CoolGuy 我添加了更多代码,请检查。
标签: c multithreading