登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
模力方舟
AI 队友
登录
注册
Gitee 2025 年度开源项目评选中
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
取消
前往登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
31
Star
72
Fork
135
openEuler
/
UniProton
代码
Issues
28
Pull Requests
15
Wiki
统计
流水线
服务
JavaDoc
PHPDoc
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
SBOM
我知道了,不再自动展开
更新失败,请稍后重试!
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
【2203 sp1】sem_wait失败
已验收
#I65O7T
缺陷
saarloos
创建于
2022-12-11 22:55
<!-- #请根据issue的类型在标题右侧下拉框中选择对应的选项(需求、缺陷或CVE等)--> <!-- #请根据issue相关的版本在里程碑中选择对应的节点,若是与版本无关,请选择“不关联里程碑”--> 【标题描述】能够简要描述问题:说明什么场景下,做了什么操作,出现什么问题(尽量使用正向表达方式) 【环境信息】 硬件信息: stm32f407 【问题复现步骤】 ```c /* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This sample test aims to check the following assertion: * * The macro PTHREAD_MUTEX_INITIALIZER can be used * to initialize mutexes that are statically allocated. * The effect are equivalent to dynamic initialization by a call to * pthread_mutex_init() with parameter attr specified as NULL, * except that no error checks are performed. * * The steps are: * * create two mutexes. One is initialized with NULL attribute, * the other is statically initialized with the macro PTHREAD_MUTEX_INITIALIZER. * * Compare the following features between the two mutexes: * -> Can it cause / detect a deadlock? (attempt to lock a mutex the thread already owns). * If detected, do both mutexes cause the same error code? * -> Is an error pthread_mutex_init_3_2_returned when unlocking the mutex in unlocked state? * When unlocking the mutex owned by another thread? * * * The test will pass if the results of each feature are the same for the two mutexes * (making no assumption on what is the default behavior). * The test will be unresolved if any initialization fails. * The test will fail if a feature differs between the two mutex objects. */ /* * - adam.li@intel.com 2004-05-09 * Add to PTS. Please refer to http://nptl.bullopensource.org/phpBB/ * for general information */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include <pthread.h> #include <semaphore.h> #include <errno.h> #include <stdio.h> #include <unistd.h> #include <stdarg.h> #include <stdlib.h> /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void pthread_mutex_init_output_init() * void pthread_mutex_init_output(char * string, ...) * * Those may be used to pthread_mutex_init_output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ /**** global variables ****/ pthread_mutex_t * pthread_mutex_init_3_2_p_mtx; int pthread_mutex_init_3_2_retval = 0; int pthread_mutex_init_3_2_returned = 0; int pthread_mutex_init_3_2_canceled = 0; sem_t pthread_mutex_init_3_2_semA, pthread_mutex_init_3_2_semB; /***** Cancelation handlers *****/ void pthread_mutex_init_3_2_cleanup_deadlk(void * arg) { pthread_mutex_init_3_2_canceled = 1; pthread_mutex_unlock(pthread_mutex_init_3_2_p_mtx); } /***** Threads functions *****/ void * pthread_mutex_init_3_2_deadlk_issue(void * arg) { int ret, tmp; if ((ret=pthread_mutex_lock(pthread_mutex_init_3_2_p_mtx))) { UNRESOLVED(ret, "First mutex lock in pthread_mutex_init_3_2_deadlk_issue"); } pthread_cleanup_push(pthread_mutex_init_3_2_cleanup_deadlk, NULL); if ((ret = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &tmp))) { UNRESOLVED(ret, "Set cancel type in pthread_mutex_init_3_2_deadlk_issue"); } if ((ret = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &tmp))) { UNRESOLVED(ret, "Set cancel state in pthread_mutex_init_3_2_deadlk_issue"); } #if VERBOSE >1 pthread_mutex_init_output("Thread releases the semaphore...\n"); #endif if ((ret = sem_post(&pthread_mutex_init_3_2_semA))) { UNRESOLVED(errno, "Sem_post in pthread_mutex_init_3_2_deadlk_issue"); } pthread_mutex_init_3_2_returned = 0; pthread_mutex_init_3_2_retval = pthread_mutex_lock(pthread_mutex_init_3_2_p_mtx); pthread_mutex_init_3_2_returned = 1; if ((ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &tmp))) { UNRESOLVED(ret, "Set cancel state in pthread_mutex_init_3_2_deadlk_issue"); } pthread_cleanup_pop(0); return NULL; } void * pthread_mutex_init_3_2_unlock_issue(void * arg) { int ret; #if VERBOSE >1 pthread_mutex_init_output("Locking in child...\n"); #endif if ((ret=pthread_mutex_lock(pthread_mutex_init_3_2_p_mtx))) { UNRESOLVED(ret, "First mutex lock in pthread_mutex_init_3_2_unlock_issue"); } if ((ret = sem_post(&pthread_mutex_init_3_2_semA))) { UNRESOLVED(errno, "Sem_post in pthread_mutex_init_3_2_unlock_issue"); } if ((ret = sem_wait(&pthread_mutex_init_3_2_semB))) { UNRESOLVED(errno, "Sem_wait in pthread_mutex_init_3_2_unlock_issue"); } if (pthread_mutex_init_3_2_retval != 0) /* parent thread failed to unlock the mutex) */ { #if VERBOSE >1 pthread_mutex_init_output("Unlocking in child...\n"); #endif if ((ret=pthread_mutex_unlock(pthread_mutex_init_3_2_p_mtx))) { FAILED("Mutex unlock pthread_mutex_init_3_2_returned an error but mutex is unlocked."); } } return NULL; } /***** main program *****/ int pthread_mutex_init_3_2(int argc, char *argv[]) { pthread_mutex_t mtx_null, mtx_macro = PTHREAD_MUTEX_INITIALIZER; pthread_t thr; pthread_mutex_t * tab_mutex[2]={&mtx_null, &mtx_macro}; int tab_res[2][3]={{0,0,0},{0,0,0}}; int ret; void * th_ret; int i; pthread_mutex_init_output_init(); #if VERBOSE >1 pthread_mutex_init_output("Test starting...\n"); #endif /* We first initialize the two mutexes. */ if ((ret=pthread_mutex_init(&mtx_null, NULL))) { UNRESOLVED(ret, "NULL mutex init"); } if ((ret=sem_init(&pthread_mutex_init_3_2_semA, 0, 0))) { UNRESOLVED(errno, "Sem A init"); } if ((ret=sem_init(&pthread_mutex_init_3_2_semB, 0, 0))) { UNRESOLVED(errno, "Sem B init"); } #if VERBOSE >1 pthread_mutex_init_output("Data initialized...\n"); #endif /* OK let's go for the first part of the test : abnormals unlocking */ /* We first check if unlocking an unlocked mutex returns an error. */ pthread_mutex_init_3_2_retval = pthread_mutex_unlock(tab_mutex[0]); ret = pthread_mutex_unlock(tab_mutex[1]); #if VERBOSE >0 pthread_mutex_init_output("Results for unlock issue #1:\n mutex 1 unlocking pthread_mutex_init_3_2_returned %i\n mutex 2 unlocking pthread_mutex_init_3_2_returned %i\n", pthread_mutex_init_3_2_retval, ret); #endif if (ret != pthread_mutex_init_3_2_retval) { FAILED("Unlocking an unlocked mutex behaves differently."); } /* Now we focus on unlocking a mutex lock by another thread */ for (i=0; i<2; i++) { pthread_mutex_init_3_2_p_mtx = tab_mutex[i]; tab_res[i][0]=0; tab_res[i][1]=0; tab_res[i][2]=0; #if VERBOSE >1 pthread_mutex_init_output("Creating thread (unlock)...\n"); #endif if ((ret = pthread_create(&thr, NULL, pthread_mutex_init_3_2_unlock_issue, NULL))) { UNRESOLVED(ret, "Unlock issue thread create"); } if ((ret = sem_wait(&pthread_mutex_init_3_2_semA))) { UNRESOLVED(errno, "Sem A wait failed for unlock issue."); } #if VERBOSE >1 pthread_mutex_init_output("Unlocking in parent...\n"); #endif pthread_mutex_init_3_2_retval = pthread_mutex_unlock(pthread_mutex_init_3_2_p_mtx); if ((ret = sem_post(&pthread_mutex_init_3_2_semB))) { UNRESOLVED(errno, "Sem B post failed for unlock issue."); } if ((ret=pthread_join(thr, &th_ret))) { UNRESOLVED(ret, "Join thread"); } #if VERBOSE >1 pthread_mutex_init_output("Thread joined successfully...\n"); #endif tab_res[i][0] = pthread_mutex_init_3_2_retval; } #if VERBOSE >0 pthread_mutex_init_output("Results for unlock issue #2:\n mutex 1 pthread_mutex_init_3_2_returned %i\n mutex 2 pthread_mutex_init_3_2_returned %i\n", tab_res[0][0],tab_res[1][0]); #endif if (tab_res[0][0] != tab_res[1][0]) { FAILED("Unlocking an unowned mutex behaves differently."); } /* We now are going to test the deadlock issue */ /* We start with testing the NULL mutex features */ for (i=0; i<2; i++) { pthread_mutex_init_3_2_p_mtx = tab_mutex[i]; tab_res[i][0]=0; tab_res[i][1]=0; tab_res[i][2]=0; #if VERBOSE >1 pthread_mutex_init_output("Creating thread (deadlk)...\n"); #endif if ((ret = pthread_create(&thr, NULL, pthread_mutex_init_3_2_deadlk_issue, NULL))) { UNRESOLVED(ret, "Deadlk_issue thread create"); } /* Now we are waiting the thread is ready to relock the mutex. */ if ((ret=sem_wait(&pthread_mutex_init_3_2_semA))) { UNRESOLVED(errno, "Sem wait"); } /* To ensure thread runs until second lock, we yield here */ sched_yield(); /* OK, now we cancel the thread */ pthread_mutex_init_3_2_canceled=0; #if VERBOSE >1 pthread_mutex_init_output("Cancel thread...\n"); #endif if (pthread_mutex_init_3_2_returned ==0) if ((ret=pthread_cancel(thr))) { UNRESOLVED(ret, "Cancel thread (pthread_mutex_init_3_2_deadlk_issue)"); } #if VERBOSE >1 pthread_mutex_init_output("Thread pthread_mutex_init_3_2_canceled...\n"); #endif if ((ret=pthread_join(thr, &th_ret))) { UNRESOLVED(ret, "Join thread"); } #if VERBOSE >1 pthread_mutex_init_output("Thread joined successfully...\n"); #endif tab_res[i][2] = pthread_mutex_init_3_2_retval; tab_res[i][1] = pthread_mutex_init_3_2_returned; tab_res[i][0] = pthread_mutex_init_3_2_canceled; } /* Now we parse the results */ #if VERBOSE >0 pthread_mutex_init_output("Results for deadlock issue:\n mutex 1 \t%s\t%s%i\n mutex 2 \t%s\t%s%i\n", tab_res[0][0]?"deadlock" : "no deadlock", tab_res[0][1]?"pthread_mutex_init_3_2_returned " : "did not return ", tab_res[0][2], tab_res[1][0]?"deadlock" : "no deadlock", tab_res[1][1]?"pthread_mutex_init_3_2_returned " : "did not return ", tab_res[1][2]); #endif if (tab_res[0][0] != tab_res[1][0]) { FAILED("One mutex deadlocks, not the other"); } if (tab_res[0][1] != tab_res[1][1]) { UNRESOLVED(tab_res[0][1], "Abnormal situation!"); } if ((tab_res[0][1] == 1) && (tab_res[0][2] != tab_res[1][2])) { FAILED("The locks pthread_mutex_init_3_2_returned different error codes."); } printf("Test PASS\n"); PASSED; } ``` 【预期结果】 测试成功 【实际结果】 测试在sem_wait失败 ```c if ((ret = sem_wait(&pthread_mutex_init_3_2_semA))) { UNRESOLVED(errno, "Sem A wait failed for unlock issue."); } ``` 这里失败 【附件信息】 比如系统message日志/组件日志、dump信息、图片等
<!-- #请根据issue的类型在标题右侧下拉框中选择对应的选项(需求、缺陷或CVE等)--> <!-- #请根据issue相关的版本在里程碑中选择对应的节点,若是与版本无关,请选择“不关联里程碑”--> 【标题描述】能够简要描述问题:说明什么场景下,做了什么操作,出现什么问题(尽量使用正向表达方式) 【环境信息】 硬件信息: stm32f407 【问题复现步骤】 ```c /* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This sample test aims to check the following assertion: * * The macro PTHREAD_MUTEX_INITIALIZER can be used * to initialize mutexes that are statically allocated. * The effect are equivalent to dynamic initialization by a call to * pthread_mutex_init() with parameter attr specified as NULL, * except that no error checks are performed. * * The steps are: * * create two mutexes. One is initialized with NULL attribute, * the other is statically initialized with the macro PTHREAD_MUTEX_INITIALIZER. * * Compare the following features between the two mutexes: * -> Can it cause / detect a deadlock? (attempt to lock a mutex the thread already owns). * If detected, do both mutexes cause the same error code? * -> Is an error pthread_mutex_init_3_2_returned when unlocking the mutex in unlocked state? * When unlocking the mutex owned by another thread? * * * The test will pass if the results of each feature are the same for the two mutexes * (making no assumption on what is the default behavior). * The test will be unresolved if any initialization fails. * The test will fail if a feature differs between the two mutex objects. */ /* * - adam.li@intel.com 2004-05-09 * Add to PTS. Please refer to http://nptl.bullopensource.org/phpBB/ * for general information */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include <pthread.h> #include <semaphore.h> #include <errno.h> #include <stdio.h> #include <unistd.h> #include <stdarg.h> #include <stdlib.h> /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void pthread_mutex_init_output_init() * void pthread_mutex_init_output(char * string, ...) * * Those may be used to pthread_mutex_init_output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ /**** global variables ****/ pthread_mutex_t * pthread_mutex_init_3_2_p_mtx; int pthread_mutex_init_3_2_retval = 0; int pthread_mutex_init_3_2_returned = 0; int pthread_mutex_init_3_2_canceled = 0; sem_t pthread_mutex_init_3_2_semA, pthread_mutex_init_3_2_semB; /***** Cancelation handlers *****/ void pthread_mutex_init_3_2_cleanup_deadlk(void * arg) { pthread_mutex_init_3_2_canceled = 1; pthread_mutex_unlock(pthread_mutex_init_3_2_p_mtx); } /***** Threads functions *****/ void * pthread_mutex_init_3_2_deadlk_issue(void * arg) { int ret, tmp; if ((ret=pthread_mutex_lock(pthread_mutex_init_3_2_p_mtx))) { UNRESOLVED(ret, "First mutex lock in pthread_mutex_init_3_2_deadlk_issue"); } pthread_cleanup_push(pthread_mutex_init_3_2_cleanup_deadlk, NULL); if ((ret = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &tmp))) { UNRESOLVED(ret, "Set cancel type in pthread_mutex_init_3_2_deadlk_issue"); } if ((ret = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &tmp))) { UNRESOLVED(ret, "Set cancel state in pthread_mutex_init_3_2_deadlk_issue"); } #if VERBOSE >1 pthread_mutex_init_output("Thread releases the semaphore...\n"); #endif if ((ret = sem_post(&pthread_mutex_init_3_2_semA))) { UNRESOLVED(errno, "Sem_post in pthread_mutex_init_3_2_deadlk_issue"); } pthread_mutex_init_3_2_returned = 0; pthread_mutex_init_3_2_retval = pthread_mutex_lock(pthread_mutex_init_3_2_p_mtx); pthread_mutex_init_3_2_returned = 1; if ((ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &tmp))) { UNRESOLVED(ret, "Set cancel state in pthread_mutex_init_3_2_deadlk_issue"); } pthread_cleanup_pop(0); return NULL; } void * pthread_mutex_init_3_2_unlock_issue(void * arg) { int ret; #if VERBOSE >1 pthread_mutex_init_output("Locking in child...\n"); #endif if ((ret=pthread_mutex_lock(pthread_mutex_init_3_2_p_mtx))) { UNRESOLVED(ret, "First mutex lock in pthread_mutex_init_3_2_unlock_issue"); } if ((ret = sem_post(&pthread_mutex_init_3_2_semA))) { UNRESOLVED(errno, "Sem_post in pthread_mutex_init_3_2_unlock_issue"); } if ((ret = sem_wait(&pthread_mutex_init_3_2_semB))) { UNRESOLVED(errno, "Sem_wait in pthread_mutex_init_3_2_unlock_issue"); } if (pthread_mutex_init_3_2_retval != 0) /* parent thread failed to unlock the mutex) */ { #if VERBOSE >1 pthread_mutex_init_output("Unlocking in child...\n"); #endif if ((ret=pthread_mutex_unlock(pthread_mutex_init_3_2_p_mtx))) { FAILED("Mutex unlock pthread_mutex_init_3_2_returned an error but mutex is unlocked."); } } return NULL; } /***** main program *****/ int pthread_mutex_init_3_2(int argc, char *argv[]) { pthread_mutex_t mtx_null, mtx_macro = PTHREAD_MUTEX_INITIALIZER; pthread_t thr; pthread_mutex_t * tab_mutex[2]={&mtx_null, &mtx_macro}; int tab_res[2][3]={{0,0,0},{0,0,0}}; int ret; void * th_ret; int i; pthread_mutex_init_output_init(); #if VERBOSE >1 pthread_mutex_init_output("Test starting...\n"); #endif /* We first initialize the two mutexes. */ if ((ret=pthread_mutex_init(&mtx_null, NULL))) { UNRESOLVED(ret, "NULL mutex init"); } if ((ret=sem_init(&pthread_mutex_init_3_2_semA, 0, 0))) { UNRESOLVED(errno, "Sem A init"); } if ((ret=sem_init(&pthread_mutex_init_3_2_semB, 0, 0))) { UNRESOLVED(errno, "Sem B init"); } #if VERBOSE >1 pthread_mutex_init_output("Data initialized...\n"); #endif /* OK let's go for the first part of the test : abnormals unlocking */ /* We first check if unlocking an unlocked mutex returns an error. */ pthread_mutex_init_3_2_retval = pthread_mutex_unlock(tab_mutex[0]); ret = pthread_mutex_unlock(tab_mutex[1]); #if VERBOSE >0 pthread_mutex_init_output("Results for unlock issue #1:\n mutex 1 unlocking pthread_mutex_init_3_2_returned %i\n mutex 2 unlocking pthread_mutex_init_3_2_returned %i\n", pthread_mutex_init_3_2_retval, ret); #endif if (ret != pthread_mutex_init_3_2_retval) { FAILED("Unlocking an unlocked mutex behaves differently."); } /* Now we focus on unlocking a mutex lock by another thread */ for (i=0; i<2; i++) { pthread_mutex_init_3_2_p_mtx = tab_mutex[i]; tab_res[i][0]=0; tab_res[i][1]=0; tab_res[i][2]=0; #if VERBOSE >1 pthread_mutex_init_output("Creating thread (unlock)...\n"); #endif if ((ret = pthread_create(&thr, NULL, pthread_mutex_init_3_2_unlock_issue, NULL))) { UNRESOLVED(ret, "Unlock issue thread create"); } if ((ret = sem_wait(&pthread_mutex_init_3_2_semA))) { UNRESOLVED(errno, "Sem A wait failed for unlock issue."); } #if VERBOSE >1 pthread_mutex_init_output("Unlocking in parent...\n"); #endif pthread_mutex_init_3_2_retval = pthread_mutex_unlock(pthread_mutex_init_3_2_p_mtx); if ((ret = sem_post(&pthread_mutex_init_3_2_semB))) { UNRESOLVED(errno, "Sem B post failed for unlock issue."); } if ((ret=pthread_join(thr, &th_ret))) { UNRESOLVED(ret, "Join thread"); } #if VERBOSE >1 pthread_mutex_init_output("Thread joined successfully...\n"); #endif tab_res[i][0] = pthread_mutex_init_3_2_retval; } #if VERBOSE >0 pthread_mutex_init_output("Results for unlock issue #2:\n mutex 1 pthread_mutex_init_3_2_returned %i\n mutex 2 pthread_mutex_init_3_2_returned %i\n", tab_res[0][0],tab_res[1][0]); #endif if (tab_res[0][0] != tab_res[1][0]) { FAILED("Unlocking an unowned mutex behaves differently."); } /* We now are going to test the deadlock issue */ /* We start with testing the NULL mutex features */ for (i=0; i<2; i++) { pthread_mutex_init_3_2_p_mtx = tab_mutex[i]; tab_res[i][0]=0; tab_res[i][1]=0; tab_res[i][2]=0; #if VERBOSE >1 pthread_mutex_init_output("Creating thread (deadlk)...\n"); #endif if ((ret = pthread_create(&thr, NULL, pthread_mutex_init_3_2_deadlk_issue, NULL))) { UNRESOLVED(ret, "Deadlk_issue thread create"); } /* Now we are waiting the thread is ready to relock the mutex. */ if ((ret=sem_wait(&pthread_mutex_init_3_2_semA))) { UNRESOLVED(errno, "Sem wait"); } /* To ensure thread runs until second lock, we yield here */ sched_yield(); /* OK, now we cancel the thread */ pthread_mutex_init_3_2_canceled=0; #if VERBOSE >1 pthread_mutex_init_output("Cancel thread...\n"); #endif if (pthread_mutex_init_3_2_returned ==0) if ((ret=pthread_cancel(thr))) { UNRESOLVED(ret, "Cancel thread (pthread_mutex_init_3_2_deadlk_issue)"); } #if VERBOSE >1 pthread_mutex_init_output("Thread pthread_mutex_init_3_2_canceled...\n"); #endif if ((ret=pthread_join(thr, &th_ret))) { UNRESOLVED(ret, "Join thread"); } #if VERBOSE >1 pthread_mutex_init_output("Thread joined successfully...\n"); #endif tab_res[i][2] = pthread_mutex_init_3_2_retval; tab_res[i][1] = pthread_mutex_init_3_2_returned; tab_res[i][0] = pthread_mutex_init_3_2_canceled; } /* Now we parse the results */ #if VERBOSE >0 pthread_mutex_init_output("Results for deadlock issue:\n mutex 1 \t%s\t%s%i\n mutex 2 \t%s\t%s%i\n", tab_res[0][0]?"deadlock" : "no deadlock", tab_res[0][1]?"pthread_mutex_init_3_2_returned " : "did not return ", tab_res[0][2], tab_res[1][0]?"deadlock" : "no deadlock", tab_res[1][1]?"pthread_mutex_init_3_2_returned " : "did not return ", tab_res[1][2]); #endif if (tab_res[0][0] != tab_res[1][0]) { FAILED("One mutex deadlocks, not the other"); } if (tab_res[0][1] != tab_res[1][1]) { UNRESOLVED(tab_res[0][1], "Abnormal situation!"); } if ((tab_res[0][1] == 1) && (tab_res[0][2] != tab_res[1][2])) { FAILED("The locks pthread_mutex_init_3_2_returned different error codes."); } printf("Test PASS\n"); PASSED; } ``` 【预期结果】 测试成功 【实际结果】 测试在sem_wait失败 ```c if ((ret = sem_wait(&pthread_mutex_init_3_2_semA))) { UNRESOLVED(errno, "Sem A wait failed for unlock issue."); } ``` 这里失败 【附件信息】 比如系统message日志/组件日志、dump信息、图片等
评论 (
1
)
登录
后才可以发表评论
状态
已验收
待办的
已挂起
修复中
已确认
已完成
已验收
已取消
负责人
未设置
标签
sig/sig-embedded
未设置
项目
未立项任务
未立项任务
里程碑
openEuler_emb-22.03-LTS-SP1-round-2
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
分支 (5)
标签 (2)
master
openEuler-24.09-HarmonyIndustry
develop-24.09
develop-23.12
openEuler-23.09
v1.0.1
v1.0.0
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
预计工期
(小时)
参与者(1)
1
https://gitee.com/openeuler/UniProton.git
git@gitee.com:openeuler/UniProton.git
openeuler
UniProton
UniProton
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册