iwanthaha 发表于 2020-1-2 15:12:54

高速线程同步低速线程有啥好办法?

各位新年好!请教问题如下:
TaskA在特定情况下需要频繁唤醒TaskB告警,TaskB是低速运行的设备(LED闪烁),TaskA频繁的进行osThreadFlagsSet会有啥不良影响?
总感觉这样做不太好,各位有啥“高速线程同步低速线程”的好办法呢?谢谢~!

代码如下:
void TaskA (void *argument)
{
    static uint32_tflags;

    while(1)
   {
       // Alarm generating ...

       if(g_Alarm)
      {
            flags = osThreadFlagsSet(ThreadIdTaskB, 1);
      }

      osDelay(10);   

    }

}

void TaskB (void *argument)
{
    static uint32_tflags;

    while(1)
   {
      flags = osThreadFlagsWait(1, osFlagsWaitAny, osWaitForever);

       LED(1);
       osDelay(500);   
       LED(0);
       osDelay(500);   

    }

eric2013 发表于 2020-1-2 15:26:08

使用事件标志的话,如果消息发的比较频繁会遗漏消息,即上次的还没有处理就又来新的了。

可以采用消息队列,但消息队列也有满的时候,此时就需要检测消息队列是否满了,满了就不可以再发了。
页: [1]
查看完整版本: 高速线程同步低速线程有啥好办法?