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

sem_lock_wait存在时间运算溢出问题 #108

Open
xkf321 opened this issue Mar 22, 2024 · 0 comments
Open

sem_lock_wait存在时间运算溢出问题 #108

xkf321 opened this issue Mar 22, 2024 · 0 comments

Comments

@xkf321
Copy link

xkf321 commented Mar 22, 2024

clock_gettime(CLOCK_REALTIME, &ts);
uint64_t ns = ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec;
ns += ms * 1000 * 1000;
ts.tv_sec = ns / (1000 * 1000 * 1000);
ts.tv_nsec = ns % 1000 * 1000 * 1000;
ret = sem_timedwait(lock, &ts);

uint64_t ns = ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec;
运行平台为arm32,计算ns 时会使用uint32类型,导致运算出现溢出, ts.tv_sec前增加强制转换为 uint64_t 可以解决

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant