linux - Share futex between unrelated processes -


how can unrelated processes cooperate using futex?

let's have unrelated processes, 1 being, say, apache subprocess module, being e.g. background script.

i'd establish condition variable mutex between 2 using futex, benefit user-space fast code path.

it seems me memory @ mutex stored in mmap'd file, if memory mapped, e.g. mlock'd 2 processes theoretically issue futex calls against same address.

alternatively, perhaps futex can passed 1 process using futex_fd.

code submissions low-, high-level , dynamic languages accepted (c, c++, python, etc.). "robust futex" api must supported too.

references:

thanks phillip , felix m. pointers.

python user code (file data structures exists, initialised pthread_process_shared)

with open("/tmp/semaphore", "rb+") f:     m = mmap.mmap(f.fileno(), 0)  # default: file, share, read-write  data = ffi.cast("unsigned long[3]", id(m))[2]  # pointer mapped area, 64-bit cpython lock = ffi.cast("pthread_mutex_t *", data) cond = ffi.cast("pthread_cond_t *", data + 40)  @contextlib.contextmanager def locked(alock):     assert not c.pthread_mutex_lock(alock)     try:         yield     finally:         assert not c.pthread_mutex_unlock(alock) 

wait , awoken:

if "wait" in sys.argv:     locked(lock):         assert not c.pthread_cond_wait(cond, lock)  elif "signal" in sys.argv:     locked(lock):         assert not c.pthread_cond_signal(cond) 

basics of setting pthread_process_shared:

l = ffi.new("pthread_mutexattr_t *") assert not c.pthread_mutexattr_init(l) assert not c.pthread_mutexattr_setpshared(l, 1)  # pthread_process_shared assert not c.pthread_mutex_init(lock, l) # same condition variable 

full code nitpicks :-) https://github.com/dimaqq/pthread_mutexattr_init/blob/master/xsem.py based on http://linux.die.net/man/3/pthread_mutexattr_init


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -