Если кто нибудь может помочь с этой программой, сдать нужно в универ.
domain com с меня.
плюс еще и хостинг дам на год.
braslavsky@hotmail.com
это задание:
Synchronization among Threads.
Abstract
The overall scenario of this assignment is implementing a producer/consumer paradigm. In this simulation the producers will generate products (strings) and add them to a bounded buffer. The consumer will simply pull those strings, store them in a database, and after the last one is stored, present them on screen. The number of producers and the amount of strings will be given in the command line.
Bounded Buffer
A bounded buffer is a data structure (similar to a Queue, FIFO order) that supports the following operations.
· Bounded_Buffer (int size) – (constructor) create a new bounded buffer with size places to store objects.
· void insert (char * s) – insert a new object into the bounded buffer.
· char * remove ( ) - Remove the first object from the bounded buffer and return it to the user.
You must implement a thread safe bounded buffer. In order to do so you will be supplied with a binary semaphore (mutex) and create a counting semaphore with two binary semaphores as studied in class. The implementation of a 'bounded buffer' synchronization mechanism, with two counting semaphores and one binary semaphore was presented in class.
For more details consult your course book or material learned in class.
Producer
The Producer has a simple job. It receives at least two parameters (you might need more than two):
1. An integer - ID
2. Amount of strings- numOfStrings
Then on creation it follows this algorithm:
For (i=0; i<numOfStrings; i++)
{
Produce a string.
Add new string to the bounded buffer.
}
Produce a 'finished' string.
Add the 'finished' string to the bounded buffer.
return 0;
The strings the producer creates are constructed as follow:
· 'product' strings the producer creates:
Producer j in iteration i creates the string: "producer j produced product number i"
· 'finished' string:
Producer j: "producer j finished"
Consumer
In this assignment their will be only one consumer. The consumer holds a Data Base (array of strings) in which it stores the received strings. The consumer will act as follow:
While (there exist a live producer)
{
Receive a string from the buffer.
Add the string to the DataBase.
}