所以我试图在这里链接任务,但是在 linux 下使用 GCC 编译时,我收到警告:分配来自不兼容的指针类型 [默认启用]。即使我只是使用相同类型的指针。
typedef struct
{
void (*routine)(void*);
void* data;
struct p_task* next;
struct p_task* prev;
int deadline;
int timeWaiting;
}p_task;
typedef struct
{
pthread_t mainThread;
pthread_t* threadArray;
int threadCount;
p_task* firstInLine;
p_task* lastInLine;
}p_pool;
void pool_add_task(p_pool* pool, void* routine, void* data)
{
// create new task
p_task* task = malloc(sizeof(p_task));
task->routine = routine;
task->data = data;
task->deadline = 5;
task->timeWaiting = 0;
// when no tasks are chained yet
if (pool->firstInLine == NULL)
{
pool->firstInLine = task;
pool->lastInLine = task;
}
else
{
pool->lastInLine->next = task; // bad line 1
task->prev = pool->lastInLine; // bad line 2
pool->lastInLine = task; // new task is last in line
}
}