【发布时间】:2016-08-05 21:37:37
【问题描述】:
我正在运行操作系统的32 bits。
现在我创建的线程将返回一个 int 值,它可能大于4G。
如何通过pthread_join() 从我的main() 函数中接收此值?
看起来在32 bits 系统中,(void *) 是 4 个字节。
#include<stdio.h>
#include<pthread.h>
#include<stdlib.h>
void* thread_function(void)
{
uint64_t nbytes = 0;
//assign values to nbytes, it could be larger than 4G.
return (void *)nbytes;
}
int main()
{
pthread_t thread_id;
uint64_t nbytes;
pthread_create (&thread_id, NULL, &thread_function, NULL);
pthread_join(thread_id,(void**)&nbytes);
}
【问题讨论】:
-
为什么不将
&nbytes作为您当前的 NULL arg 发送到pthread_create并通过函数中的地址简单地转换和设置值? -
首先您的
thread_function类型错误。它应该有论据。现在猜猜是什么?您可以使用这些参数来回传递值。void*返回类型实际上并不打算转换为非指针类型。