Skip to content

fix: tooldata mutex init - give before try#3832

Open
smoe wants to merge 1 commit intoLinuxCNC:2.9from
smoe:fix_tooldata_mutex_init
Open

fix: tooldata mutex init - give before try#3832
smoe wants to merge 1 commit intoLinuxCNC:2.9from
smoe:fix_tooldata_mutex_init

Conversation

@smoe
Copy link
Collaborator

@smoe smoe commented Feb 25, 2026

explicitly initialize the mutex, instead of calling tool_mmap_mutex_give() without a prior lock.

Mutex is “given” without an initial successful “try/get” In src/emc/tooldata/tooldata_mmap.cc:163, tool_mmap_creator() calls tool_mmap_mutex_give() right after setup without any prior lock acquisition. According to the man page this is unusual and potentially undefined depending on rtapi_mutex semantics.

I am not sure about how much of a bug this is, but there should be an initial assignment of mutex, right?

@smoe smoe added bug for-discussion-only This pull request is intended as a basis for discussion, not to be merged as-is v2.9 candidate Things that would be nice to have for 2.9 2.10-candidate would be nice to have fixed in 2.10 labels Feb 25, 2026
explicitly initialize the mutex, instead of calling tool_mmap_mutex_give() without a prior lock.

Mutex is “given” without an initial successful “try/get”
In src/emc/tooldata/tooldata_mmap.cc:163, tool_mmap_creator() calls tool_mmap_mutex_give() right after
setup without any prior lock acquisition. That is unusual and potentially undefined depending on rtapi_mutex semantics.
@BsAtHome
Copy link
Contributor

This is a mutex that can be "given" when not held.

That said, the solution is not to remove the mutex give, but to add the mutex get in line 157 to protect the actual block that needs protecting.

@BsAtHome
Copy link
Contributor

Strike my last... You should just leave it as is.

The 'give' actually initializes the mutex. Is simple clears the mutex unconditionally because you do not need to hold it to run 'give' on it.

@smoe smoe removed bug v2.9 candidate Things that would be nice to have for 2.9 2.10-candidate would be nice to have fixed in 2.10 labels Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

for-discussion-only This pull request is intended as a basis for discussion, not to be merged as-is

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants