本帖最后由 zeshoufx 于 2019-7-17 16:00 编辑
如题,想通过RTTHREAD系统建一个线程,然后将其挂起,延时一段时间后,在将该线程恢复,挂起成功,恢复时,发现一直被空闲线程占用,,恢复不了,有人懂吗
/*
rtthread
*/
#include "board.h"
#include "rtthread.h"
static rt_thread_t led1_thread=RT_NULL;
//static rt_thread_t usart_thread=RT_NULL;
static void led1_thread_entry(void *parameter);
//static void usart_thread_entry(void *parameter);
int main(void)
{
led1_thread=rt_thread_create("led1",led1_thread_entry,RT_NULL,512,3,20);
if(led1_thread!=RT_NULL)
{
rt_thread_startup(led1_thread);
}
else
{
return -1;
}
}
static void led1_thread_entry(void *parameter)
{
rt_err_t uwret=RT_EOK,uwresum=RT_EOK;
while(1)
{
led1=1;
rt_thread_delay(500);
rt_kprintf("led1_thread is running,LED1_ON\r\n");
led1=0;
rt_thread_delay(500);
rt_kprintf("led1_thread is running,LED1_OFF\r\n");
rt_thread_delay(5000);
rt_kprintf("挂起LED1线程!\r\n");
uwret=rt_thread_suspend(led1_thread);
if(uwret==RT_EOK)
{
rt_kprintf("挂起LED1线程成功!\r\n");
}
else
{
rt_kprintf("挂起LED1线程失败!\r\n");
}
rt_thread_delay(5000);
rt_kprintf("恢复LED1线程!\r\n");
uwresum=rt_thread_resume(led1_thread);
if(uwresum==RT_EOK)
{
rt_kprintf("恢复LED1线程成功!\r\n");
}
else
{
rt_kprintf("恢复LED1线程失败!\r\n");
}
rt_thread_delay(5000);
}
}
|