Question: Program has to be in C++ Q) Create a system with parallel processes that will use a ring buffer. The parent process must create the

Program has to be in C++

Q) Create a system with parallel processes that will use a ring buffer. The "parent" process must create the semaphore set and segment and start its child, then it can back off and wait for the others to finish. Create a process that reads characters from the keyboard and writes them to the ring buffer, you must create a process that generates text and places it on the ring buffer, and you must create a process that reads from the ring buffer and writes to the screen. All necessary resources must be synchronized.

code below is an half written code, where i need to impliment rest, whats is asked in the question above.

#include #include "RingBuffer.h" #include #include

template class RingBuffer { public: RingBuffer(size_t size): mObject(size), mHead(0), mTail(0) bool Put(T&c object) { if (!IsFull()) { mObjects[mTail] = object; mTail = (mTail + 1) % mObjects.size(); return true; } return false; }

bool Get(T* object) { if (peek(object)) { mHead = (mHead + 1) % mObjects.size(); return true } return false; } bool Peek(T* object) const { if (!IsEmpty()) { *object = mObjects[mHead]; return true; } return false; } bool IsEmpty() const { return mHead == mTail; }

bool IsFull() const { return ((mTail + 1) % mObjects.size()) == mHead;

}

size_t() const { return (mTail < mHead) ? (mTail + mObjects.size() - mHead): (mTail - mHead); }

private: std::vector mObjecrs; std::atomicmHead; std::atomicmTail; };

int main() {

RingBuffer buffer(10); char input_char = 'x'; buffer.Put(input_char);

char tmp_char; std::cout << "Could peek: " <

std::cout <<"Size: " <

std::cout <<"Coud get: " << budder.Get(&tmp_char) << std::endl;

std::cout << "Value feathced: " << tmp_char << std::endl; std::cout << "Size: " <

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!