Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion libr/util/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ static void *_r_th_launcher(void *_th) {
}
r_th_lock_enter (th->lock);
if (th->delay) {
r_sys_sleep (th->delay);
ut32 delay = th->delay;
th->delay = 0;
r_th_lock_leave (th->lock);
while (delay > 0 && !th->breaked) {
r_sys_usleep (10000);
delay = (delay > 10) ? delay - 10 : 0;
Comment on lines +50 to +55
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The delay calculation has a unit mismatch. The delay field is documented as "delay the startup of the thread for at least N seconds" (libr/include/r_th.h:170), and the old code used r_sys_sleep(th->delay) which expects seconds. However, the new code sleeps for 10ms intervals and decrements delay by 10 each iteration, effectively treating delay as if it's in units of 10ms rather than seconds. This means a delay of 5 seconds would only sleep for 50ms (5 iterations * 10ms), instead of the intended 5000ms.

To fix this, the delay should be converted to milliseconds or the decrement should be adjusted accordingly. For example, convert delay to milliseconds initially (multiply by 1000), then decrement by 10 each iteration.

Suggested change
ut32 delay = th->delay;
th->delay = 0;
r_th_lock_leave (th->lock);
while (delay > 0 && !th->breaked) {
r_sys_usleep (10000);
delay = (delay > 10) ? delay - 10 : 0;
/* th->delay is in seconds; convert to milliseconds for 10ms steps */
ut32 delay_ms = th->delay * 1000;
th->delay = 0;
r_th_lock_leave (th->lock);
while (delay_ms > 0 && !th->breaked) {
r_sys_usleep (10000);
delay_ms = (delay_ms > 10) ? delay_ms - 10 : 0;

Copilot uses AI. Check for mistakes.
}
r_th_lock_enter (th->lock);
}
if (th->breaked) {
th->running = false;
Expand Down
Loading