How can unrelated processes cooperate using a futex?
Let's say I have unrelated processes, one being, say, an apache subprocess with my module, another being e.g. a background script.
I'd like to establish a condition variable with a mutex between the two using a futex, to benefit for user-space fast code path.
It seems to me that memory at which mutex is stored could be in a mmap
'd file, if that memory is mapped, e.g. mlock
'd the two processes could theoretically issue futex calls against same address.
Alternatively, perhaps a futex can be passed from one process to another using FUTEX_FD
.
Code submissions low-, high-level and dynamic languages are accepted (C, C++, Python, etc.). "robust futex" API must be supported too.
References:
Thanks Phillip and Felix M. for pointers.
Python user code (file with data structures already exists, initialised with
PTHREAD_PROCESS_SHARED
)Wait and get awoken:
Basics of setting
PTHREAD_PROCESS_SHARED
:Full code for nitpicks :-) https://github.com/dimaqq/pthread_mutexattr_init/blob/master/xsem.py based on http://linux.die.net/man/3/pthread_mutexattr_init