Skip to content

[Bug] ART-Pi Smart 平台 alarm() 定时相对现实时间不准确 | Inaccurate Timing of alarm() #9264

Open
@polarvid

Description

@polarvid

RT-Thread Version

master

Hardware Type/Architectures

ART-Pi Smart Board

Develop Toolchain

GCC

Describe the bug

Compile the following code snippet and run the program in userspace:

#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>

int main() {
    // 信号集合
    sigset_t set;
    int sig;

    // 初始化信号集合
    sigemptyset(&set);
    sigaddset(&set, SIGALRM);

    // 阻塞 SIGALRM 信号,确保 sigwait 可以捕获到该信号
    if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) {
        perror("sigprocmask");
        exit(EXIT_FAILURE);
    }

    // 设置闹钟,3 秒后触发 SIGALRM 信号
    alarm(3);

    // 等待 SIGALRM 信号
    printf("Waiting for the alarm...\n");
    if (sigwait(&set, &sig) == 0) {
        printf("Alarm triggered! Signal number: %d\n", sig);
    } else {
        perror("sigwait");
        exit(EXIT_FAILURE);
    }

    // 收到信号后继续执行
    printf("Program continues after alarm.\n");

    return 0;
}

Other additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Arch: ARM/AArch64BSP related with armRT-SmartRT-Thread Smart related PR or issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions