【发布时间】:2021-01-05 16:05:13
【问题描述】:
我这几天一直在尝试解决这个问题,但无法解决。我正在使用 CCS 作为 IDE,并且正在使用 Windows。我正在尝试在 MSP432 上创建一个 RTOS 内核,并且需要使用 pthreads。我已经能够在其他示例中使用 pthreads,但我正在尝试编写自己的程序,并且在构建时遇到了这个问题:
unresolved symbol pthread_create, first referenced in ./armrtk/src/task.obj
我已将文件路径包含在 CCS 中,但我无法使用 .cfg 文件,因为我没有使用 XDCTools。我只需要这方面的帮助,我非常感谢。 我也收到警告:
in pthread_create in TASK.C: #169-D argument of type "void *" is incompatible with parameter of type "void *(*)(void *)"
TASK.H
#ifndef TASK_H
#define TASK_H
#include <pthread.h>
struct task_t {
pthread_t* thread;
int threadCheck;
int state;
};
void *task1(void);
void *task2(void);
struct task_t *create_task(void* functionptr);
void delete_task(void *task);
#endif
TASK.C
#include <task.h>
#include <stdlib.h>
#include <pthread.h>
#define BLOCKED -1
#define READY 0
#define RUNNING 1
int testValue1 = 0;
int testValue2 = 0;
struct task_t *new_task;
pthread_t pntr;
struct task_t *create_task(void* functionptr) {
new_task = malloc(sizeof(struct task_t));
if(!new_task)
return NULL;
//set State of the new thread to ready
new_task->state = 0;
// check to see if pthread is created
**new_task->threadCheck = pthread_create(new_task->thread, NULL, functionptr, NULL);**
if(new_task->threadCheck!= 0){
//thread failed
return NULL;
}
return new_task;
}
void delete_task(void *task) {
if(task != NULL){
free(task);
pthread_exit(NULL);
}
}
【问题讨论】:
-
我看不到如何从 pthreads 创建 RTOS 内核。 AFAIK,实际 POSIX 操作系统之外的大多数 pthreads(POSIX 线程)实现都是现有本机 RTOS 之上的一层。如果 pthreads 可用,则您要么已经拥有 RTOS,要么线程支持不支持实时,并且尝试从它顶部创建 RTOS 注定要失败。 RTOS 的主要功能是多线程/任务,因此创建 RTOS 内核必须实现线程 - 您不能仅通过包含 pthreads.h 就神奇地获得线程,即使那样您也必须链接库。跨度>
-
"我已经包含了文件路径...";什么“文件路径”?到什么文件?您了解 pthreads.h 不是 库吗?您需要链接 libpthreads.a,但我怀疑这是否可行; pthreads 需要底层 RTOS 来提供线程支持;您不能从 pthreads 创建RTOS。先有鸡,后有蛋。
标签: embedded kernel rtos msp432