Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions