我正在尝试在 Arduino Uno 上使用原型(prototype)线程。 我正在关注https://techtutorialsx.com/2017/12/30/esp32-arduino-using-the-pthreads-library/ 。
我已经下载了 pthread.h 头文件并将其放在与 .ino 文件相同的目录中。
我已将教程中的 #include 语句更改为 #include "pthread.h",因为该文件与我的 .ino 文件位于同一目录中。
我收到以下错误:
Protothreading_example:11:4: error: 'pthread_t' was not declared in this scope
pthread_t threads[4];
^
Protothreading_example:16:37: error: 'threads' was not declared in this scope
returnValue = pthread_create(&threads[i], NULL, printThreadId, (void *)i);
^
Protothreading_example:16:79: error: 'pthread_create' was not declared in this scope
returnValue = pthread_create(&threads[i], NULL, printThreadId, (void *)i);
^
exit status 1
'pthread_t' was not declared in this scope
我有两个后续问题:
1)是否有更好的 Arduino 原型(prototype)线程教程资源?
2) 我需要从多个传感器读取数据并分别处理。由于 Arduino 不支持硬件级别的多线程,因此我做了另一个实现,用计时器循环遍历函数指针数组。这种方法与原型(prototype)线程相同吗?
最佳答案
您提到的教程适用于 ESP32,它具有与 Arduino Uno 本身不同的 Arduino 内核。它主要包含 FreeRTOS,它为该库提供了底层机制。它不能按原样与 Arduino Uno 一起使用。
我相信您的应用程序不需要多线程。您可以循环遍历传感器读数并在循环结束时对其进行处理。向并发迈出的一步是使用 simple scheduler .
关于c - Arduino Uno 上的原型(prototype)线程/多线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56273691/