ESP-IDF中调用xEventGroupWaitBits函数失效问题的分析(1)
笔者在使用ESP-IDF时,在自己的工程中遇到了一个十分奇怪的问题:
在代码中调用xEventGroupWaitBits函数时,一开始没有问题,但当任务挂起(suspend)又恢复(resume)后,原本应该阻塞住的XEventGroupWaitBits函数竟然能够“漏过去”,其下的打印居然能够显示出来。
上边说得简单明了,但实际上笔者一点点缩小范围、逐步定位,再到总结出以上发现,用了将近一整天时间。
为了验证这个问题,笔者专门做了一个测试例程(把原来工程中的大量不相关的代码略去),其中只包括了很简单原始的几个函数。代码如下:
/*
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
#include <stdio.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
#include "esp_system.h"
#include "esp_log.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#define BIT_DEVICE_CREATE_DONE (1U