How do I protect a character string in shared memory between two processes?

Since you have two processes you need a cross-process synchronisation object. I think this means that you need to use a mutex.

You cannot use a Critical Section because these can only be used for synchronization between threads within the same process. For inter process synchronization you need to use a Mutex or a Semaphore. The difference between these two is that the former allows only a single thread to own a resource, while the latter can allow up to a maximum number (specified during creation) to own the resource simultaneously.In your case a Mutex seems appropriate.

Thank you for the clarification about the CS, that makes sense. – Tommy Aug 9 at 21:47.

A mutex object facilitates protection against data races and allows thread-safe synchronization of data between threads. A thread obtains ownership of a mutex object by calling one of the lock functions and relinquishes ownership by calling the corresponding unlock function. If you are using boost thread, you can use it's mutex and locking, more to read see the link below: boost.org/doc/libs/1_47_0/doc/html/threa....

No boost, but thanks for the info.... – Tommy Aug 9 at 21:44.

Since you're talking about two processes, system-wide mutexes will work, and Windows has those. However, they aren't necessarily the most efficient way. If you can put more things in shared memory, then passing data via atomic operations on flags in that memory should be the most efficient thing to do.

For instance, you might use the Interlocked functions to implement Dekker's Algorithm (you'll probably want to use something like YieldProcessor() to avoid busy waiting).

Nice, thanks for the link.... – Tommy Aug 10 at 0:24 I recently got a book about synchronization like this (I got it from Amazon, so I didn't realize it was synchronization like this: amazon. Com/Method-Multiprogramming-Monographs-Computer-Science/… ). They kept referring to Peterson's algorithm ( en.wikipedia.Org/wiki/Peterson%27s_algorithm ) because it can be generalized.

Personally, I would use system-wide mutexes for anything other than a toy program. But the question asked for efficiency, and I believe this fits the bill. – Max Lybbert Aug 10 at 7:53.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions