Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

Writing c program using PThreads,synchronization and deadlock prevention. 

i'm supposed to prepare 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.

ex 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?

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M9128671

Have any Question?


Related Questions in C/C++

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As