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.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 21SA
icon
Related questions
Question
100%

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".
    1. Write a C implementation of the problem and solution of the synchronization problem you are responsible with.

    2.  

      1. Prepare a report as above given details.

      Your code must run without any error to be evaluated; otherwise, this grade will be deducted.

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

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]);
    }
}

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

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

    1. Recommended page length is 5 without cover and references pages.

        1. 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 the algorithm 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 your

        implementation.

        1. PREPARE A REPORT AS ABOVE GIVEN DETAILS!!!

 

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning