Question

I want to this question solution by programming c code. I need this solution as soon...

I want to this question solution by programming c code. I need this solution as soon as possible i have to submit this code after 24 hours. please someone help this question thanks :D

Programming Question: (15pts)

Assume a finite number of resources of a single resource type must be managed. Processes may ask for a number of these resources and will return them once finished. If all resources are in use the request is denied and the process terminates. Ensure thread safety by using mutex locks – be sure to only include necessary code inside the critical section. The maximum number of resources and the number of available resources are declared as follows:

#define RESOURCES 10

int available_resources = RESOURCES;

Create 5 threads which will be requesting resources (process and thread is used interchangeably in the description of this problem). Apart from your main function, create 3 functions to perform the following tasks:

request_resources – this function will receive the requested number of resources and determine if the request can be filled or not, if the request is filled the number of available_resources must be adjusted, if it not filled return -1 to indicate the request was not filled.

release_resources – this function will receive the number of resources the process is releasing and will adjust the number of available_resources.

process_manager – each process will execute this function. The purpose of this function is to randomly determine the number of resources the process is going to request (random number between 1 and 5), call the request function to determine if the request if filled.

If the request is filled, print out a message indicating the number of resources the process is allocated, wait for up to 3 seconds (randomly determine the time), and then call the release function to indicate the process is done with the resources. Print out a message indicating how many resources were released, terminate the process.

If the request is denied, print out an appropriate message and terminate the process.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

gets (s) tv s.fen (uij);

Add a comment
Know the answer?
Add Answer to:
I want to this question solution by programming c code. I need this solution as soon...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Part 3. IPC (InterProcess Communication) Programming In Part 3, you are asked to develop a multit...

    Part 3. IPC (InterProcess Communication) Programming In Part 3, you are asked to develop a multithreaded program and a Makefile to automate the compilation on Linux platform. This assignment assists you for better understanding of processes and threads management, multithreaded programming, and enhancing programming skills and experience with programming on a Unix-like environment. You are asked to implement a multithreaded producer-consumer problem with PThreads library in this programming assignment. The producer-consumer is a common problem that requires cooperating processes or...

  • Can someone help create this program for Linux. Part 3. IPC (InterProcess Communication) Programming In Part...

    Can someone help create this program for Linux. Part 3. IPC (InterProcess Communication) Programming In Part 3, you are asked to develop a multithreaded program and a Makefile to automate the compilation on Linux platform. This assignment assists you for better understanding of processes and threads management, multithreaded programming, and enhancing programming skills and experience with programming on a Unix-like environment. You are asked to implement a multithreaded producer-consumer problem with PThreads library in this programming assignment. The producer-consumer is...

  • I need this code in C programming. Can anyone pls help me in this? Project 8,...

    I need this code in C programming. Can anyone pls help me in this? Project 8, Program Design A hotel owner would like to maintain a list of laundry service requests by the guests. Each request was stored with the room number, the guest's first name, last name, and number of items. The program laundry_list.ccontains the struct request declaration, function prototypes, and the main function. Complete the function definitions so it uses a dynamically allocated linked list to store the...

  • operating system engineering , please read the question and solve on the given skeleton code ....

    operating system engineering , please read the question and solve on the given skeleton code . Write a multi-threaded program with Semaphores as counters and pthread_mutex_t mutex to solve the producer-consumer problem: A bounded buffer is simply a global integer array of size N (2) which can be accessed by multiple threads. • Create two types of threads - Producer (2) and Consumer (2). Producers will write to the buffer, and the consumers will read the buffer. In this scenario,...

  • Multi-threaded programming help!!! Can anyone solve this problem? It has to be written in C, runs...

    Multi-threaded programming help!!! Can anyone solve this problem? It has to be written in C, runs on Linux. his time you need to rewrite a multithreaded Pthread program that works with sleep() or pthread_join() in order to print out Fibonacci sequences properly. Create a folder name, WK6 on your class Linux machine when you work. gcc assignment3.c-Wall -Werror -pthread You are required to develop your own program using C with the following information Need to declare a function that receives...

  • In c programming The Consumer Submits processing requests to the producer by supplying a file name, its location and a character. It also outputs the contents of the file provided by the producer...

    In c programming The Consumer Submits processing requests to the producer by supplying a file name, its location and a character. It also outputs the contents of the file provided by the producer to the standard output. The Producer Accepts multiple consumer requests and processes each request by creating the following four threads. The reader thread will read an input file, one line at a time. It will pass each line of input to the character thread through a queue...

  • I need a help to solve this problem I want to create a code that implement bounded buffer problem by using semaphore. so...

    I need a help to solve this problem I want to create a code that implement bounded buffer problem by using semaphore. so use int buffer[10]; // buffer is global variable and buffersize is 10 and there is only one producer and one consumer. 1) Producer() - At every 200msec, generates random positive integer and add to the buffer. - Then print current state of buffer (numbers and in/out indices) -Also print current state of two semaphore which are full...

  • I need help writing a C programming code. I am trying to create a program that...

    I need help writing a C programming code. I am trying to create a program that returns ANY given number's decimal value as an Integer (Whole number). Examples: User input: 0.35 Output: 35 User input: 1.465 Output: 465 User input: 10.6054 Output: 6054

  • C programming Game of life GAME !!!! I need some code for this function : /*...

    C programming Game of life GAME !!!! I need some code for this function : /* * get_grid creates new memory for a "grid". * x is the height and y is the width. */ char** get_grid(int x, int y){ } /* * print_grid attempts to print an x height * by y width grid stored at the location * provided by grid */ void print_grid(int x, int y, char** grid){ }

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT