Writing c program using pthreads synchronization


Writing c program using PThreads,synchronization and deadlock prevention. 

i'm supposed to write small program for ticket sale company/agency

Passenger_can:Make reservations for themselves;cancel reservations for themselves;view the(reserved/bought) ticket;buy tickets only for themselves.
Agents_can: Make Reservations for any passenger;Cancel reservation for any passenger; View all the seats;Buy tickets for any passenger

The important point is to preserve the consistency in passenger accounts during concurrent access to the seats via operations using suitable synchronization primitives.

implement such a plane ticket agency simulation performed during a period, using Pthreads library primitives. Each passenger and agent of the system should be implemented as a separate thread. At the end of the simulation, the initial thread prints out the summary of the simulation as described in the Details section.

DETAILS
o You should implement each passenger and agent as a separate thread. The initial main thread is responsible for creating passenger/agent threads, managing them, and displaying the final results as soon as the simulation completes.

o Note that, shared resources among multiple passengers/agents (i.e. threads) are plane seats, and preserving consistency and preventing deadlocks are major issues.

o We suggest you to pick the number of operations and operation types to be performed by each passenger/agent in random manner in your simulation.

o The total simulation time is D days. All the transactions within that period will be logged in a file.

o There are P passengers, A agents, and N planes with unique IDs used by the ticket system. Seats in a single plane also have unique IDs 1 to M.

o Number of simulation days, passengers, agents, and planes would be taken from the input file. Input file format is described below.

o Assume that, in your implementation 20 seconds correspond to one simulation day. o All agents know the IDs of all the passengers. These agents can perform any operation for any passengers.

o A passenger can perform an operation only for himself.

o The plane service has a limitation for the tickets that can be bought during a day for each passenger. In total, a passenger cannot buy more than the given limit for her/him during a day. However, there is no such limit for reservation.

o If a reserved ticket is not bought within 2 days, reservation is cancelled automatically. o Each passenger can have at most 10 tickets bought (reserved ones are not counted) for
each plane throughout the simulation.

o In your implementation of buy/reserve (multiple) tickets operations, make sure that a solution for deadlock prevention is taken into account. Note that you should not use a semaphore/lock for the whole plane just to reserve/buy/cancel a ticket for a single/multiple passenger. You should use synchronization primitives such that "independent operations" are performed concurrently.

o Multiple simultaneous view operations (i.e. reads) on an account should be allowed in your synchronization solution. However the other operations, buy, reserve, cancel (i.e. updates) should be performed in a mutually exclusive way.

o When the simulation is finished for the given number of days, the following should be available in a log file:

o For each transaction, there should be a line of information in the log file in the following format:

P_ID N_ID S_ID O_ID Operation Simulation_Day

o Number of transactions performed by each passenger and agent at each day o Total number of transactions of each passenger and agent. 

o Number of empty seats at each plane.

Example Input File Format:

Below first line: 

first digit(4) :Number of passengers 
second digit(6): Number of agents
third digit(6): Number of simulation days 
fourth digit (2):Number of Planes
fifth, last digit(30): Number of seats in a plane
---------------------------------------
4,6,6,2,30 

1* 5**
2 4 
3 4 
4 3 
5 6

*First digit(1) is P_ID 
**Second digit(5) is DayLimit

P_ID : Passenger ID
N_ID : Plane ID
S_ID : Seat ID
O_ID : ID of the person that performed the operation

DayLimit: Maximum number of tickets that can be bought for a single plane during a day. If DayLimit of a customer is not specified for a passenger, default value is 4.

any help will be appreciated, just telling me the logic behind it, the logic flow, how to prevent deadlock, if two agents wanna reserve the same place at the same time?

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: Writing c program using pthreads synchronization
Reference No:- TGS0128671

Expected delivery within 24 Hours