Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] pthread_cancel线程无法退出 #9881

Open
wycwyhwyq opened this issue Jan 7, 2025 · 6 comments
Open

[Bug] pthread_cancel线程无法退出 #9881

wycwyhwyq opened this issue Jan 7, 2025 · 6 comments
Labels
Arch: RISC-V BSP related with risc-v BSP: K230 BSP related with K230

Comments

@wycwyhwyq
Copy link
Contributor

RT-Thread Version

c9c103f

Hardware Type/Architectures

risc-v c908

Develop Toolchain

GCC

Describe the bug

调用pthread_cancel线程无法退出,附上测试代码

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <pthread.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>

pthread_t tid;

static void *subthread(void *arg)
{
    while (1) {
        usleep(1000000);
        printf("%s: %d\n", __func__, __LINE__);
    }

    return 0;
}

int main(int argc, char **argv)
{
    pthread_create(&tid, NULL, subthread, 0);

    while (getchar() != 'q')
        usleep(10000);

    printf("%s: %d\n", __func__, __LINE__);
    pthread_cancel(tid);
    printf("%s: %d\n", __func__, __LINE__);
    pthread_join(tid, NULL);
    printf("%s: %d\n", __func__, __LINE__);

    return 0;
}

Other additional context

No response

@unicornx unicornx added the Arch: RISC-V BSP related with risc-v label Jan 7, 2025
@unicornx
Copy link
Contributor

unicornx commented Jan 7, 2025

什么板子上发现的?

@wycwyhwyq
Copy link
Contributor Author

什么板子上发现的?

CanMV-K230

@unicornx
Copy link
Contributor

unicornx commented Jan 9, 2025

什么板子上发现的?

CanMV-K230

你用的什么 bsp 在测试?是 bsp/k230 吗?我怎么听说这个 bsp 在 canMV 上跑不起来的?

@wycwyhwyq
Copy link
Contributor Author

什么板子上发现的?

CanMV-K230

你用的什么 bsp 在测试?是 bsp/k230 吗?我怎么听说这个 bsp 在 canMV 上跑不起来的?

bsp/k230系列的板子都可以复现,可能和板子没有关系,我定位到问题大概是在musl lib的cancel信号处理部分
loH94YH51d
这里会导致被cancel的线程一直接收到信号

@heyuanjie87
Copy link
Contributor

通过qemu调试用户态发现pthread_kill这个函数一直被调用,看c库代码里是没有循环调用的

@heyuanjie87
Copy link
Contributor

编译c库的时候关闭优化(-O0)pthread_cancel能正常退出,但pthread_join无法退出(被挂起在了pthread->detach_state的futex上)

@Rbb666 Rbb666 added the BSP: K230 BSP related with K230 label Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch: RISC-V BSP related with risc-v BSP: K230 BSP related with K230
Projects
None yet
Development

No branches or pull requests

4 participants