While looking at some codebases on github I have seen that sometimes a mutex table is used instead of local mutexes, selecting a mutex from this table based on, for example, pointer or hash of some other variable & an integer to differentiate the "order" of locks.
My guess is that it is done to avoid creating & destroying mutexes all over the place to improve efficiency, but wouldn't that also create situations where multiple unrelated objects are trying to lock the same mutex & thus need to wait for an unrelated lock to be released as well as waiting for their own lock?
This could potentially be solved by using a very large table, but wouldn't that potentially waste a lot of memory and potentially system resources to just have hundreds of unused mutexes sitting around? Or is this not a big issue overall?
I tried looking it up but all that google gives me is "how to use a mutex" and similar stuff.
EDIT: By "local" I mean, a mutex that is not from a global table and is individually created whenever it is needed instead of picking an existing one from a table.