Re: Shared memory and semaphores

Is IPC mechanism using shared memory and semaphores for synchronous simplex pipes or duplex message queues?

0


a source to share


2 answers


If my understanding of your question is correct, it is duplex.



With shared memory, both processes could communicate in both ways, not just one, as a reader and as a writer. Pipes are read-only or write-only, but you can overcome this by using two pipes (although message queues are the best option).

0


a source


The semaphore works like this ... proc a: "Is the resource available?" Semaphore = -2 Yes. semaphore ++ proc b: "Is resource ..." semaphore = -1 Yes. semaphore ++ proc c: "is resource ..." semaphore = 0 No (nothing happens)

at this point proc c might be queued (depending on your api, it might be a busy cycle or it might be a callback, or you might just create a waiting thread and write your own callback)

proc a: "im done" semaphore -;



proc c will notice that the semaphore is accessible via something similar to what I mentioned earlier.

the reason I wrote all of this is, so I can say, both. It's like a message queue where you can have threads waiting on a resource (semaphore-managed shared memory) that trigger some action, even an actual system message, when they receive the resource. Or you could just get busy - wait until it's over and it looks like a pipeline.

0


a source







All Articles