From bd2281e935e29c1df08688c88ee158a178e9805c Mon Sep 17 00:00:00 2001 From: Zhao Chong Date: Fri, 26 Jul 2019 12:28:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BC=82=E6=AD=A5=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E6=A6=82=E7=8E=87=E6=80=A7=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=97=A5=E5=BF=97=E4=B8=8D=E5=AE=8C=E6=95=B4?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: [背景]:异步输出模式开启、断言开启,elog_async.c在初始化时,elog_async_init创建子线程完成后, 子线程处理函数async_output在一开始会对全局变量init_ok进行断言,如果为false,那么就无法进入 后续sem_wait流程,进行结果输出了;而init_ok是在子线程创建完之后,elog_async_init最后才设置 为true的,这样程序的正确执行就取决于父子线程的调度顺序了 [解决办法]:子线程的处理程序中无需对init_ok进行判断,因为在while循环体中sem_wait会保证只有在 有需要输出的内容时,才会触发后续的内容输出过程 --- easylogger/src/elog_async.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/easylogger/src/elog_async.c b/easylogger/src/elog_async.c index 6df5f3a..cade4bf 100644 --- a/easylogger/src/elog_async.c +++ b/easylogger/src/elog_async.c @@ -283,8 +283,6 @@ static void *async_output(void *arg) { size_t get_log_size = 0; static char poll_get_buf[ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE]; - ELOG_ASSERT(init_ok); - while(true) { /* waiting log */ sem_wait(&output_notice);