【发布时间】:2021-07-23 18:11:51
【问题描述】:
#include <stdio.h>
#include <stdlib.h>
// Thread Declarations
#include <pthread.h>
pthread_t monitor_thread;
void *Get_Monitor_Data(void *BM_params);
// this is my struct ///
typedef struct
{
HCORE BM_cores[0];
int total_cores;
} BM_PARAMS;
BM_PARAMS BM_Dat;
int Start_monitor(void)
{
int RETVAL=0;
RETVAL = pthread_create(&monitor_thread, NULL, Get_Monitor_Data,(void*)BM_Dat);
if(RETVAL !=0)
{
printf("Error Starting Thread \n");
}
return 0;
}
void *Get_Monitor_Data (void *BM_Dat) // Bus Monitor Thread
{
BM_PARAMS*monitor_params;
int no_of_cores=0;
monitor_params = (BM_PARAMS *) BM_Dat;
BTICard_CardReset(*monitor_params->BM_cores);// reset card if required
return 0;
}
pthread 创建部分给出“无法转换为指针类型”的错误 我做错了什么吗? 我需要将一个结构作为参数传递给 P 线程函数,我该怎么做?
【问题讨论】:
-
什么是
monitor_thread?您还声称您已经“在我的主要内容之前声明了 Get_Monitor_Data”,这在帖子中没有显示。请提供完整准确的代码minimal reproducible example 以及准确完整的错误消息。 -
它必须是
&BM_Dat作为pthread_create的最后一个参数 -
当时我尝试更改为 &BM_Dat Eclipse 无法识别包含文件中的函数
-
G:\Projects\Eclipse Resources\BM Ballard\BM_BALLARD\Debug/..\BallardBM/BM_BALLARD.c:46:未定义对
BTICard_CardOpen' G:\Projects\Eclipse Resources\BM Ballard\BM_BALLARD\Debug/..\BallardBM/BM_BALLARD.c:60: undefined reference toBTICard_CoreOpen' G:\Projects\Eclipse Resources\ 的引用BM Ballard\BM_BALLARD\Debug/..\BallardBM/BM_BALLARD.c:64:未定义对“BTI1553_ChIs1553”的引用 -
这是一个完全不同的问题。发布一个新问题。
标签: c multithreading pointers struct pthreads