Question ab/ multiple producers/consumers

Question ab/ multiple producers/consumers

Post by chwan » Sun, 24 Nov 1996 04:00:00



I am doing a project about a shared memory for multiple
producers and consumers. So far I have done a producer
and a consumer sharing a memory without any problem.

However, when I fork the second producer in producer(), and/or
the second consumer in consumer(), I can't get the correct
result. The 2nd producer overwrites what the 1st producer
had done, and when the 2nd consumer access the share memory, the
1st consumer automatically receives what the 2nd consumer had
taken.

Can someone kindly show me some suggestions?
Thank you very much in advance if there are some.

 
 
 

Question ab/ multiple producers/consumers

Post by » Sun, 24 Nov 1996 04:00:00


Quote:> However, when I fork the second producer in producer(), and/or
> the second consumer in consumer(), I can't get the correct
> result. The 2nd producer overwrites what the 1st producer
> had done, and when the 2nd consumer access the share memory, the
> 1st consumer automatically receives what the 2nd consumer had
> taken.

Are you serialising the processes? If more than one process can read
and/or write the same shared memory, you should use some technique that
guarentees exactly one process at time will execute the read or write
(which is called serialising). One way is to require each process down an
IPC style semaphore before access and then raise it after. Another is to
lock a well known file before and then unlock it after. There are probably
others.

You can also use IPC queues to communicate in a serialised fashion.

--
Where walks their Brother wan and lone  |For the time being, email
who marched from halls of marbled stone?|   to me might be lost or
The Brothers brood their bristling mood;|    delayed. Email to the
their anger grows till air will moan.   |sender will definitely go

 
 
 

1. Producers/Consumers and shared memory/semaphores

Anyone,
I'm looking for a site or resource that will help me with a programming
project in C to
solve a lab for an OS class. I'm to write a program that is similar to the
init process except that
it takes as an argument an initfile which contains the name of a program
that spawns child
processes and implements producers and consumers.  The main program prints
out pid's,
index numbers of the shared segments, date/time and a generic producer or
consumer statement.
I have some resources such as Stevens' "Advance Programming in the Unix
Environment"
but I still need something/someone to bounce ideas off of.
Thanks in advance.
Kent

2. Adobe Acrobat reader for linux

3. Producer/Consumer Problem

4. PATCH: eliminate use of ide_ioreg_t on ARM

5. producer/consumer problem

6. Adaptec 1505a not recognized

7. "producer - consumer" problem

8. Apache Web Server Questions?

9. Producer Consumer problem

10. Use semaphore for producer/consumer case...

11. New multithread producer/consumer library

12. Semaphores and consumer/producer problem

13. Multi-value semaphore: a producer-consumer problem