【发布时间】:2017-03-07 02:50:36
【问题描述】:
我正在编写 C/C++ 代码来练习 PThreads。我正在研究我导师的例子。我收到一个错误。我不知道该怎么做。错误是:无效的从‘void*’到‘pthread_t*’的转换,它是由malloc行引起的。
我遗漏了一些代码。 thread_count 是一个全局变量,它的值在命令行中被捕获。
#include <cstdlib>
#include <cstdio>
#include <sys/time.h>
#include <pthread.h>
int main(int argc, char *argv[])
{
// this is segment of my code causing error
// doesn't like the third line of code
static long thread;
pthread_t* thread_handles;
thread_handles = malloc(thread_count*sizeof(pthread_t));
}
【问题讨论】:
-
C 或 C++,选择一种语言。它们是不同的语言。
标签: c++ parallel-processing pthreads