The mutex module uses $BASHPID to identify the owner of a mutex,
causing scripts to be unable to unlock a mutex that was created in a
subshell (which is what happens when using the ipc module).
This commit changes the mutex module to use $$ to identify the owner
of a mutex, allowing child processes to unlock their parent's mutexes
and vice-versa.
mutex_trylock() {
local lock="$1"
- if ! ln -s "$BASHPID" "$lock" &> /dev/null; then
+ if ! ln -s "$$" "$lock" &> /dev/null; then
return 1
fi
return 1
fi
- if (( owner != BASHPID )); then
+ if (( owner != $$ )); then
return 2
fi