首页 > > 详细

代写Assignment #5代写Java程序

项目预算:   开发周期:  发布时间:   要求地区:

Assignment #5

Assignment Overview

Black Friday is almost here! You are managing the local electronics store, and you know that Black Friday is always a crazy day in your store. You want to ensure that the shopping experience is a safe one for everyone. To that end, you've decided to control the flow of customers into and within your store. Customers will be grouped at one of two entryways, and then will be escorted to the area of the store they wish to shop in to maintain some semblance of order.

● Escort Team O can accommodate up to 100 shoppers.

Escort Team 1 can accommodate up to 50 shoppers.

There are 500 shoppers lined up at the main entrance (Zone O), and they all want to get to one of the other four zones.

50 shoppers want to get to Zone 1 (Appliances).

100 shoppers want to get to Zone 2 (TVs).

250 shoppers want to get to Zone 3 (Smartphones).

100 shoppers want to get to Zone 4 (Video Games).

The 500 shoppers waiting at the main entrance (Zone O) will need to be escorted to the other four zones by one of the two escort teams. However, only one escort team can be in any zone at one time to avoid confusion.

For this assignment, write a C program which will simulate this activity.

Purpose

Learn how to use multi-threading and mutual exclusion to safely update shared values.

Get experience with either

o pthread_mutex_init(), pthread_mutex_lock(), pthread_mutex_unlock() and pthread_mutex_destroy () system functions; OR

o sem_init (), sem_wait (), sem_post () and sem_destroy () system functions.

Gain more experience with the C programming language from an OS perspective.

Instructions

Attached to this assignment is a tarball with the following files in it. None of these files should be modified:

Makefile <—- A pre-packaged Makefile. This tells you how your progran should be structured.

un-assignnent. sh <—- A shell script. that will autonatically run your progran.

Download this tarball and upload it to GAUL. Extract the tarball (tar -xvfassignment-5. tar). Change to the assignment-5 directory.

You will write a program called assignment-5. c. This program will:

Initialize 5 shopping zones with requested shoppers and 2 escort teams with capacities as defined above.

Create two threads (one for each escort team).

o Starting at Zone O, attempt to enter a zone. When the escort team has permission to enter:

■ If there are shoppers waiting to enter the store (Zone O), the escort team will gather as many shoppers as possible.

If there are shoppers to drop off at a zone and the escort team's group already has shoppers in it:

Escort as many shoppers as possible to Zones 1, 2, 3, and 4.

If there are more shoppers in the group to escort but the zone has no more shoppers to add, move to the next zone.

If there are no more shoppers in the group to escort, the escort team will move back (zone-by-zone) to Zone O to gather more shoppers.

o When all shoppers have been escorted to their chosen zones, the thread can simply quit.

Important notes and requirements:

Gathering and escorting shoppers takes a bit of time. Simulate this with the sleep () function. Gathering or escorting 100 shoppers takes 10 minutes (which can be simulated as 10 seconds). Gathering or escorting 50 shoppers takes 5 minutes (which can be simulated as 5 seconds). And so on. Since we have 500 shoppers, the whole program should take ~50-90 seconds to run with some potential variance depending on how often the threads need to wait on one another. (You can relax this requirement to speed up your testing, but the final version should include the sleep () function to help ensure some variance between Escort Team O and Escort Team 1.)

There are 6 resources that cannot be shared in this project:

o STDOUT Zone 0

o Zone 1

o Zone 2

o Zone 3

o Zone 4

If an escort team is in a zone, the other escort team cannot be in the same zone.

If a thread is printing information to the screen, the other thread cannot print to the screen. This will ensure threads do not print out on top of one another and creates a smooth print out to the screen.

As long as an escort team is in a zone, it should also have full control of STDOUT. This means that, for example, if Escort Team O is ready to enter Zone O and Escort Team 1 is ready to enter Zone 1, then only one of the threads gets to print to the screen. The other thread must wait until it can get control of STDOUT.




软件开发、广告设计客服
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 9951568
© 2021 www.rj363.com
软件定制开发网!