Skip to content

hal: read threads_running once per thread pass - #4896

Merged
BsAtHome merged 1 commit into
LinuxCNC:masterfrom
grandixximo:thread-start-race
Nov 24, 2026
Merged

BsAtHome merged 1 commit into
LinuxCNC:masterfrom
grandixximo:thread-start-race

Conversation

@grandixximo

Copy link
Copy Markdown
Contributor

thread_task() reads hal_data->threads_running twice: once to decide on the init pass, once for the cyclic pass. A start that lands between the two reads runs the cyclic functions once before the init functions. The init pass that follows runs no cyclic functions, so one cycle is missing for every function on the thread.

The fix reads it once per pass.

I found it with the virtual time of #4893 under load: timedelta reported a maximum of two periods in about one run out of a hundred, and none in 130 runs with the fix. I have no deterministic test for it; the window is two adjacent reads. The thread, HAL and rtapi tests pass.

thread_task() read hal_data->threads_running twice: once to decide on
the init pass, once for the cyclic pass. A start that lands between the
two reads runs the cyclic functions once before the init functions, and
the init pass that follows runs no cyclic functions, so that cycle is
missing for every function on the thread.

Read it once per pass.

Seen with the virtual time of LinuxCNC#4893 under load: timedelta reported
a maximum of two periods in about one run out of a hundred, none in
130 runs with the fix.
@BsAtHome
BsAtHome merged commit ec90568 into LinuxCNC:master Nov 24, 2026
18 of 19 checks passed
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

Successfully merging this pull request may close these issues.

2 participants