Forums Programming Assignment Help I need a c program using posix threads immediately

This topic contains 0 replies, has 1 voice, and was last updated by  Anonymous 6 years, 6 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #8302

    Anonymous

    “Hi. I need a c program using posix threads immediately within 5 hours. The specification is as belows. Please reply immediately with a qoute. This is very urgent.

    In a typical gasoline filling station, there are multiple pumps drawing from a single tank. Slightly complicating the situation, there are usually only two different grades of fuel stored in the tanks: the lowest and highest grades. However, each pump is capable of delivering fuel from the highest-grade tank; the lowest-grade tank; or a blend of the two for an intermediate grade. Implement a thread-based parallel implementation simulating a large gas station in which up to 20 pumps are all delivering fuel from the two storage tanks, and intermittently a delivery truck adds fuel to the tanks.

    Your program needs to have two types of threads. There will be exactly 1 refueling thread created. There must be at least 1 pump thread and at most 20. The number of pump threads will be specified on the command line. Your program must check for a valid number of pump threads as a part of your error checking. If an incorrect number of pump threads is specified your program should display an error message and exit appropriately.

    Each tank holds 1000 gallons of fuel. All requests are for whole gallons of gasoline (no partial amounts). Pump threads can request fuel from either tank (high grade or low grade) or can request fuel from both tanks in the case of the medium grade. In the case of a medium grade, the mixture is approximately 50-50. For example, if a pump thread request is for 8 gallons, then the request will be satisfied by removing 4 gallons each from the high grade and low grade tanks. If a pump thread request is for 9 gallons, then the request will be satisfied by removing 5 gallons of high grade and 4 gallons of low grade.

    Unfortunately, the piping distribution from the tanks to the pumps only allows for only one (1) pump thread to be attached to either tank in the case of high or low grade gasoline or for only one (1) pump thread to be attached to both tanks in the case of medium grade. (This actually simplifies the problem ;^) )

    All threads are created at successful program startup. Both tanks are filled each to 1000 gallons of fuel at successful program startup. Pump threads are assumed to have a full tank of gas during each cycle. So in order to simulate cars arriving at a pump randomly, design a busy wait function with random valued input parameters to simulate the random arrival of a car to a pump. After “”driving around”” the point pump threads will create a request of what type of gasoline grade and amount of fuel. The type and amount are randomly determined using a thread safe random number generator. The amount of fuel requested must be between 2 and 10 gallons inclusive. After every 10 successful fill-ups a refueling thread is allowed to preempt all pump threads and check the amount of each tank. If the level of any (or both) tank(s) is 250 gallons or below, the refueling thread completely refills the tank(s). No pump thread is permitted to fill up during the refueling process.

    After 5 re-filling cycles of each tank your simulation is to end. Remaining threads will be permitted to complete their fill-up requests and then exit.

    You may want to display output indicating the activity in each thread. This should also be a command line parameter. A sample run of this simulation is given below (you are free to design your own output format as long as it is readable).

    % pumpsim 22 YES

    pumpsim: incorrect number of pump threads (22): value must be between 2 and 20 inclusive %

    % pumpsim 4 YES

    4 pump threads created

    1 refueling thread created

    1000 gallons in each tank

    Simulation beginning…

    PUMP 0: 5 gallons of LOW grade

    PUMP 1: 10 gallons of LOW grade

    PUMP 2: 7 gallons of HIGH grade

    PUMP 0: 4 gallons of LOW grade

    PUMP 0: 8 gallons of LOW grade

    PUMP 3: 3 gallons of MEDIUM grade

    … and so on…

    RE-FUELING: LOW grade tank is 248 gallons

    …and so on…

    Simulation Complete…

    At the completing of your simulation, your program needs to output the following information:

    The number of completed fill-ups per thread.

    The number of times each tank was filled up.

    The total number of high grade gallons consumed.

    The total number of medium grade gallons consumed.

    The total number of low grade gallons consumed.

    Design your program such that your simulations does not simulate real-time! These simulations should execute with reasonably speed.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.