我试图用我的线程函数内部的主功能分配的内存,但我得到的错误:undefined reference to 'product_line'
如何共享内存在一个线程中
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include "test1.c"
int main()
{
char** product_line;
product_line = malloc(sizeof(char *));
product_line[0] = "Toy";
product_line[1] = "Chair";
product_line[2] = "Door";
pthread_t thread_tid;
pthread_create(&thread_tid, NULL, foo, NULL);
pthread_join(thread_tid, NULL);
return 0;
}
这是单独的源线程电话:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
extern char** product_line;
void * foo(void *param)
{
int i;
printf("%s\n", product_line[0]);
for (i = 0; i < 3; i++)
printf("%s\n", product_line[i]);
}
我该如何解决这个错误?
包含'.c'源文件是不寻常的。 – MikeCAT
您为一个指针分配空间,然后使用其中的三个:(( –
)我应该使用其他方法来包含文件吗? –