PLEASE, WRITE A C++ FILE WITH THE REQUIREMENTS THAT ARE GIVEN BELOW: THE PROBLEM YOU ARE GOING TO WRITE THE CODE OF IT IS "The Cigarette Smokers". Write a C implementation of the problem and solution of the synchronization problem you are responsible with. Prepare a report as above given details. Your code must run without any error to be evaluated; otherwise, this grade will be deducted.
PLEASE, WRITE A C++ FILE WITH THE REQUIREMENTS THAT ARE GIVEN BELOW:
- THE PROBLEM YOU ARE GOING TO WRITE THE CODE OF IT IS "The Cigarette Smokers".
-
Write a C implementation of the problem and solution of the synchronization problem you are responsible with.
-
-
Prepare a report as above given details.
Your code must run without any error to be evaluated; otherwise, this grade will be deducted.
-
-
Step by step
Solved in 3 steps
Hello, can you rewrite the code about the same problem "The Cigarette Smokers" by inspiring from the given code. This is a dining code and its output goes infinitely. I want you to write the code of the cigarette problem depending on this code.
#include <stdio.h>
#include <semaphore.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#define MIN(a, b) ((a<b) ? a:b)
#define MAX(a, b) ((a>b) ? a:b)
#define N 5
sem_t forks[N];
int philosophers[N] = {0, 1, 2, 3, 4};
int STEP = 0;
void *live(void *args);
int main()
{
pthread_t threads[N];
for (int i = 0; i < N; i++)
{
sem_init(&forks[i], 0, 1);
pthread_create(&threads[i], NULL, live, &philosophers[i]);
}
for (int i = 0; i < N; i++)
{
pthread_join(threads[i], NULL);
sem_destroy(&forks[i]);
}
return 0;
}
void *live(void *args)
{
int *id = (int *)args;
while (1)
{
sem_wait(&forks[MIN(*id, (*id + 1) % N)]);
sem_wait(&forks[MAX(*id, (*id + 1) % N)]);
printf("%d Philosopher %d is eating...\n", STEP, *id);
STEP += 1;
if (STEP % N == 0)
{
printf("---\n");
}
sem_post(&forks[(*id + 1) % N]);
sem_post(&forks[*id]);
}
}
CAN YOU ALSO WRITE ITS REPORT PLEASE
WRITE THE REPORT OF THE GIVEN PROBLEM BELOW:
-
You are asked to prepare a detailed report about your project
-
-
Recommended page length is 5 without cover and references pages.
-
-
Provide at least the below sections in your report. You can add more sections if you need.
• Introduction
Explain the problem you are assigned to. How it relates to Operating Systems? Which area of
Operating System does thealgorithm provide the solution? Explain in detail.-
Methodology
Explain your solution with pseudo-codes in detail. -
Implementation
Demonstrate your code with a simulation. Explain step-by-step which functions are invoked. Do not write any code in this section, but use only function names. Show your run results.
-
Conclusion
Summarize the report. Discuss the efficiency of the algorithm and yourimplementation.
-
PREPARE A REPORT AS ABOVE GIVEN DETAILS!!!
-
-
-