How to implement ring buffer concept in the shared memory

How to implement ring buffer concept in the shared memory

Post by barkh » Fri, 22 Dec 2006 13:29:05


Hi All,

I need to write and read the variable size strings into and from the
shared memory.

Take for example

There are 10 child processes acting as a producer
C1, C2..... C10

There is 1 parent process acting as a consumer
P1

There is one shared memory created in windows using file mapping object
by the parent process .

All the child processes wants to write variable size bytes ( array of
characters ) into the shared memory and simoultaneously the parent
process needs to consume them.

Can anyone please suggest me the way to organize the reading and
writing the string to the shared memory keeping in mind the
synchronization.

I want to know how can i maintain shared memory header section that
will give information to the child and parent process to write and read
simoultaneously to the shared memory.

I want to implement something like ring buffer concept in the shared
memory.
Read this link to understand the ring buffer concept.

http://www.yqcomputer.com/ ~afb/20012/cs1/slides/queue-03.html
http://www.yqcomputer.com/

Thanks
 
 
 

How to implement ring buffer concept in the shared memory

Post by Gary Chans » Fri, 22 Dec 2006 15:08:12


That's basically how I'd implement it, too. A FIFO queue implemented as
a ring buffer, with a mutex to synchronize access. Done properly, since you
have only one reader, you only need the mutex to synchronize the writers.
Actually, in one program where I implemented something like this, I used
InterlockedCompareExchange instead of a mutex and I synchronize the reader
just in case there might be more then one (to make the DLL more general
purpose).

- Gary Chanson (Windows SDK MVP)
- Abolish Public Schools