Question: Please write a C code for the following problem with all the required instructions: Implement the Roller Coaster problem in C (not C++) ensuring the
Please write a C code for the following problem with all the required instructions:
Implement the Roller Coaster problem in C (not C++) ensuring the constraints are met and critical sections are properly protected. The program must compile and execute under Ubuntu 22.04 LTS. The Roller Coaster scenario is a concurrent programming problem that can be solved using semaphores1 and is summarized below. This code requires multi-threading, semaphores, and possibly overcoming deadlocks.
Suppose there are n passenger threads and one roller coaster car thread. The car can hold at most c passengers, where c n. Each passenger would ride the roller coaster for a random number of times, and the random number is in the range [0, i]. After each ride, the passenger will wait for a random time in the range [0s, 10s] to brace themselves. After completing their predetermined number of iterations, the passenger will exit the park (i.e., the thread terminates).
Upon deciding to ride a roller coaster, the passenger must wait for an open seat to ride the roller coaster car. The car waits for passengers for a maximum of 2s. Upon completing 2s or reaching the maximum capacity, the car goes around the track for 5s. The roller coaster shuts down (the car thread exits) after all passengers exit the park.
You will create one thread for each user and one thread for the car. The car thread will allow passenger boarding for 2s or until the car is full. Once the boarding closes, the car goes on a ride for 5s, represented by a sleep function call. The pseudo code for the car thread can be found below:

Each user thread will wait for a random time in the rage [0, 10s] and then attempt to board the car. During the boarding process, the user checks to see if the car is boarding passengers. If the car is not boarding, the user thread will have to wait until the car is boarding. If the car is boarding passengers, the user can check to see if a seat is available. If the seat is available, the user can take the seat. However, if the seat is unavailable, the user will have to wait in the queue until the car finishes a loop and there are empty seats. The Pseudo code for the passenger thread can be found on the next page.
Pseudo code for the car and passenger:

The total number of passengers, n, the number of passengers per car, c, and the upper bound on the maximum number of iterations of a passenger, i, will be accepted as command line arguments. The accepted arguments should meet the following constraints: c 0.
Include Files: In order to use threading functions and semaphores in C, you will need the below include files: #include
Compilation options: user the following compilation options:
gcc -Wall -g -pedantic -pthread -o roller roller.c
Example Output: the following are some execution examples showing error handling and an example execution. Successive execution may vary. The $ is the prompt.

Correct output showing program execution:

C Get Options Example: Below is an example use of the getopt() function for reference:

Car: Passenger: max i ter = random (0,i); while (j : Wooh! I'm about to ride the roller coaster for the jth time! I have max_iter j iterations left. \033[0m )
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
