473,325 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Barber Shop

1
simulation of the sleeping barber problem. The given program first creates a barber thread. The barber thread calls callNext to get a customer, waits a random amount of time (to simulate the time it takes to cut hair), and then repeats the process.
After the barber thread is created, the program creates customer threads at random intervals. The customer threads call enter to enter the shop and then wait for the barber to complete the haircut (using a barrier for synchronization).

Your task is to write code for callNext and enter so the barber sleeps when there are no customers waiting and the customers wait if the barber is busy or leave if the shop is full. BarberShop has instance variables waiting and activity to help you keep track of how many customers are waiting and what the barber is doing, as well as condition variables customers and barber used to synchronize the two types of threads. There is also a mutex called mutex you can use to enforce mutually exclusive access to the instance variables. callNext should

check for waiting customers
if there are none, wait
if there are waiting customers, signal one
enter should
check the state of the barber and the number of waiting customers
wake (signal) the barber if no one else is waiting and the barber is asleep
leave the shop if the shop is full (or closed)
wait if the barber is cutting and there is room left in the shop
Jan 4 '08 #1
1 5154
r035198x
13,262 8TB
Please read the guidelines for asking for help on homework questions.
Jan 4 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: SpamProof | last post by:
I got an animated gif that is a barber pole spinning that I want to use as a progress bar. The problem is that is stops spinning (shows 1 frame) when my browser is processing a submited request...
2
by: John Dalberg | last post by:
I installed the Pet Shop 4.0 app. However everytime I try to create a new user, I get a "Please enter a more secure password" error. I tried all kinds of passwords. I looked at the membership...
52
by: Steve Holden | last post by:
I've been thinking (and blogging) about python evangelism since PyCon, as a result of which I created a squidoo lens: http://www.squidoo.com/pythonlogy Imagine my surprise at discovering that...
56
by: richard | last post by:
So I wrote PyPI back a couple of years ago. It was just a simple cgi script and some distutils code. I needed to call it *something* and "Python Package Index" seemed like a fairly obvious name....
0
by: Chris Stephens | last post by:
We are celebrating with a cake and sticky wine...... We thought of sending portions out with each sale but TCP/IP has not yet been extended to the "Matter Transmission Protocol" so instead we are...
1
by: bangaw | last post by:
Could someone pls. send me a simple sleeping barber program. i'll be gladly 2 pay for it. assignment is due friday.. and they want it in visual c++ for windows. THANKS!!!!
0
by: vamsikrishnaatluri | last post by:
in the old sleeping barber problem ther is a small modification wherein there is a special customer who need not wait in the waiting hall but enters the saloon directly.. and if if no chair is empty...
7
by: Daniele | last post by:
Hi I want to build a shop from scratch, i'm laying down all the possible problem i can find during the way. how can i structure the database to be able to add unlimited properties or attribute to...
2
by: birendra00 | last post by:
any one has code for simulation of sleeping barber problem using pthreads
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.