This README gives a brief overview about all provided scripts and their respective tasks. For even more detailed description on the code, please refer to the respective script itself
The task-specific elements (only being RealConsumer
and RealProducer
) can be easily replaced by other task-specific implementations without the need to change all other scripts
Implements a class that is responsible for the ring buffer consumers and producers use. pushItem()
and popItem()
are saved by respective condition variables
. If the buffer is filled to the max, then all producers wait until new space is available (if a consumer takes out an object). If now consumers are provided, then all producers will wait forever (infinitive loop).
Given functioanilities:
pushItem()
- pushes given item (reference) into BufferpopItem()
- gets last item (being the first that was pushed in) from the BufferresetBuffer()
- resets the whole Buffer be resetting both indizes (head
andtail
)isEmpty()
- checks if Buffer is emptyisFull()
- checks if Buffer is fullgetCapacity()
- returns capacity of BuffergetElementCount()
- returns the number of elements in Buffer
Special:
popItem()
has a timeout. This is important to be able to end a respective consumer. Otherwise all consumers would work infinitively long. Every consumer stops itself if the buffer is empty for a given amount of time (here 1.5s) --> throws Runtime Error afterwards- Data-Type of stored obejcts can be chosen via given
<template T>
Header responsible for all Image manipulations that are needed for rendering of the resulting Fern
CMake file, responsible for compiling. Gets called by Makefile
Implements a class for a basic Consumer
in the producer - consumer model. Does not contain task-specific functionality (concerning the BarsnleyFern), defining the abstract functionality of a Consumer, being the parent class of RealConsumer
, inheriting from Worker
. Is a <template T>
class because of the DataType of the Points (that is changing the type of the Buffer
)
Given functionality:
step()
- takes virtual classstep()
fromWorker
and implements it --> worker function that does the actual workconsume()
- abstract function that gets overwritten byRealConsumer
, consuming the provided elements from the bufferfinishWork()
- abstract function that finishes the work after allConsumer
s have done their tasks
Special:
step()
is responsible to stop the producers. Catches the Runtime Error thrown by theBuffer
. Stops respective producer afterwards
Implements the Point objects (used by RealProducer
and RealConsumer
). Here a point consists of a pair of floats.
Given functionality:
getNextPoint()
- determines the next point, depending on current point and given distribution. In here, the four affine transformations (shown below) are implemented
Header of Point.cpp
Implements a class for a basic Producer
in the producer - consumer model. Does not contain task-specific functionality (concerning the BarsnleyFern), defining the abstract functionality of a Producer, being the parent class of RealProducer
, inheriting from Worker
. Is a <template T>
class because of the DataType of the Points (that is changing the type of the Buffer
)
Given functionality:
step()
- takes virtual functionstep()
fromWorker
and overwrites it by implementing --> worker function that does the actual workconsume()
- abstract function that gets overwritten byRealProducer
, producing the elements, pushing the into the buffer
Special:
step()
is responsible to stop the producers. Trigger to stop the producers is given byRealProducer
(if the respective one has produced enough elements)
Implements the RealConsumer, doing the task-specific consuming actions, inherits from Consumer
. Resulting image has a resolution of 10k x 20k pixels in .png
format. Uses one mutex per row (= 10k mutexes) to make parallel writing on one single iamge threadsafe
Given functionality:
consume()
- takes virtual functionconsume()
fromConsumer
and overwrites it by implementing --> does the actual consume: Takes the data points provided by theProducer
s via theBuffer
and draws them respectively onto the resulting photofinishWork()
- takes virtual functionfinishWork()
fromConsumer
and overwrites it by implementing --> saves the image that has been drawn. Only done once, by lastRealConsumer
createImage()
- initializes the iamge that shall be drawn (only done once, saved by mutex)convert2Pixel()
- converts the given point (fromProducer
, respectiveBuffer
) and converts it into pixel values for the image. Performs a scaling and bias on x and y, depending on desired image size
Header of RealConsumer.cpp
Implements the RealProducer, doing the task-specific consuming actions, inherits from Producer
Given functionality:
produce()
- takes virtual functionproduce()
fromProducer
and overwrites it by implementing --> does the actual produce: calculates new points that shall be drawn onto the picture given the respective affine transformations inPoint.cpp
Special:
produce()
is responsible to stop the Producers when enough points (here 10^8) are calculated and stored in the Buffer
Implements a class for a basic Worker
. Does not contain task-specific functionality (concerning the BarsnleyFern), defining the abstract functionality of a Worker, being the parent class of Consumer
and Producer
. Implementing the actual parallelism of the whole project. Is aware of starting, stopping and regularly calling the seperate Workers
Given functionality:
join()
- joins the the thread (that has been initialized and started bystart()
). Waiting for respective thread to finish before callingstop()
and finishing the Workerstart()
- initializing and starting the actual threadstop()
- stopping the thread, deconstructing itwork()
- actual working function that gets called bystart()
. Runs whatever gets implemented in abstract functionstep()
isRunning()
- checks if Worker is already runningisTerminated()
- checks if Worker is terminatedstep()
- abstract function that gets overwritten byProducer
respectiveConsumer
, performing the actual algorithm
Header of Worker.cpp
Main function of the whole project. Defines number of consumers and producers (here both to be 2), initialises Buffer, RealConsumers and RealProducers and starts the latter.