c - Synchronize two processes using two different states -


i trying work out way synchronize 2 processes share data.

basically have 2 processes linked using shared memory. need process set data in shared memory area, process b read data , act on it.

the sequence of events looking have is:

  1. b blocks waiting data available signal
  2. a writes data
  3. a signals data available
  4. b reads data
  5. b blocks waiting data not available signal
  6. a signals data not available
  7. all goes beginning.

in other terms, b block until got "1" signal, data, block again until signal went "0".

i have managed emulate ok using purely shared memory, either block using while loop consumes 100% of cpu time, or use while loop nanosleep in misses of signals.

i have tried using semaphores, can find way wait zero, not one, , trying use 2 semaphores didn't work. don't think semaphores way go.

there numerous processes accessing same shared memory area, , processes need notified when shared memory has been modified.

it's trying emulate hardware data , control bus, events edge rather level triggered. it's transitions between states interested in, rather states themselves.

so, ideas or thoughts?

linux has own eventfd(2) facility can incorporate normal poll/select loop. can pass eventfd file descriptor process process through unix socket usual way, or inherit fork(2).

edit 0:

after re-reading question think 1 of options signals , process groups: start "listening" processes under same process group (setpgid(2)), signal them negative pid argument kill(2) or sigqueue(2). again, linux provides signalfd(2) polling , avoiding slow signal trampolines.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -