Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Write the C code for the below two systems programming questions: Question 1. A factory is producing socks. Use lock(s) and condition variable(s) to write a procedure ASockIsProduced(), which is...

1 answer below »

Write the C code for the below two systems programming questions:


Question 1. A factory is producing socks. Use lock(s) and condition variable(s) to write a procedure ASockIsProduced(), which is called whenever a sock (thread) is produced. As soon as two socks are available, one thread should call PackAPair() (you don’t need to implement PackAPair()), and two threads should return from ASockIsProduced.


Question 2. A factory is producing pepper and salt shakers. Use lock(s) and condition variable(s) to write a procedure PepperShakerArrvies() that is called whenever a pepper shaker (thread) is produced. Use lock(s) and condition variable(s) to write another procedure SaltShakerArrives() that is called whenever a salt shaker (thread) is produced. As soon as one pepper shaker and one salt shaker are available, one of the threads should call PackShakers() (you don’t need to implement PackShakers()); one thread is returned from PepperShakerArrives() and one thread is returned from SaltShakerArrives().

Answered Same Day Oct 12, 2022

Solution

Aditi answered on Oct 12 2022
48 Votes
SOLUTION
1.
Include header file
#include #include #include class SockFactory
{
public:
static void main(std::vecto
std::string> &args)
{
SockFactory* sockFactory = new SockFactory();
Thread thread1 = java.lang.Thread(sockFactory.new SockFactory::SockProducer::SockProducer());
Thread thread2 = java.lang.Thread(sockFactory.new SockFactory::SockProducer::SockProducer());
thread1.start();
thread2.start();
}
private:
static int NUM_SOCKS;
Lock lock = java.util.concu
ent.locks.ReentrantLock();
Condition socksAvailable = lock.newCondition();
int socksProduced = 0;
public:
void ASockIsProduced()
{
lock.lock();
try
{
socksProduced++;
if (socksProduced % 2 == 0)
{
socksAvailable.signalAll();
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here