answersLogoWhite

0


Best Answer

#define CHAIRS 5 /* # chairs for waiting customers */

typedef int semaphore; /* use your imagination */

semaphore customers = 0; /* # of customers waiting for service */

semaphore barbers = 0; /* # of barbers waiting for customers */

semaphore mutex = 1; /* for mutual exclusion */

int waiting = 0; /* customer are waiting (not being cut) */

void barber(void)

{

while (TRUE) {

down(&customers); /* go to sleep if # of customers is 0 */

down(&mutex); /* acquire access to "waiting' */

waiting = waiting - 1; /* decrement count of waiting customers */

up(&barbers); /* one barber is now ready to cut hair */

up(&mutex); /* release 'waiting' */

cut_hair(); /* cut hair (outside critical region */

}

}

void customer(void)

{

down(&mutex); /* enter critical region */

if (waiting < CHAIRS) { /* if there are no free chairs, leave */

waiting = waiting + 1; /* increment count of waiting customers */

up(&customers); /* wake up barber if necessary */

up(&mutex); /* release access to 'waiting' */

down(&barbers); /* go to sleep if # of free barbers is 0 */

get_haircut(); /* be seated and be served */

} else {

up(&mutex); /* shop is full; do not wait */

}

}


User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How to write c programme of Sleeping-barber problem in opertating system?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you become software engineer after tenth?

lose of health like louse ur eyes ,digest system,heart problem, neck problem....etc


What operating system utilities did you use or could you have used to solve the problem?

windows xp


What is the effect of insulation failure in three phase system?

ground faults are the most common problem.


Difference between system analyst and system designer?

system analyst is a person who investigates the system and identifies the components that are required to realize the system.and identifies those roles. where as designer specifies how to solve the problem specified in requirement analysis.


How do you stop excessive crank case pressure on a high compression race engine that already has a crank case evacuation system?

If you have a crankcase evacuation system on it other than a standard PCV valve and breather, such as a vacuum pump and oil separator or header collector EVAC system, and you are still having the problem such as blowing out the dipstick tube and such then you may have another problem such as a bad ring, bad cam bearing, or oiling problem such as leaving the oil pump dry or cracked pick up tube. If you have a crankcase evacuation system on it other than a standard PCV valve and breather, such as a vacuum pump and oil separator or header collector EVAC system, and you are still having the problem such as blowing out the dipstick tube and such then you may have another problem such as a bad ring, bad cam bearing, or oiling problem such as leaving the oil pump dry or cracked pick up tube.

Related questions

For bank system which opertating system is best?

As we have to go with high security and no wastage of time at employees work place it is better and best to opt UNIX or its flavors as the operating system


Is assembler a system programme?

noo


What is mean by operating system?

operating system is a set of computer programme.


Who was founded as system analysis and programme development?

SAP


What is a cold start in computing terms?

Cold start in computing terms mean to start a computer programme from the very beginning. It is a potential problem in the computer based information system.


A system programme that translate and executes an instruction simultaneously is know as?

An interpreter


Multitasking vs Multiprogramming?

Multi programming is to open the more than one programme in one computer system. Muli tasking is to use the more than one programme in one computer system.


What is the conclusion of property management system?

the programme is best for all hospitality businesses


What are the feature of unix operating system?

flexibe, faster to run programme ,very secure , portability


What are Features of unix operating system?

flexibe, faster to run programme ,very secure , portability


What is bugs and back doors?

Two very different considerations. A bug is an unexpected error in programme execution. Named for a real bug, a moth that got caught in a mechanical relay in an early computing system. photos exist of the unfortunate animal. [It was a trig routine that was interfered with.]A back door is a guaranteed way into a programme, such that no matter in what condition the programme was misbehaving, entry could be guaranteed to effect a remedy. Or at least to understand the problem. Keenly sought for by hackers for illicit entry.


What is perverse software?

It is a programme which is causing hindrances of other programme executionin such a way resulting in modifiction or complete destruction of datawithout the user's intention or even sabotaging the operational system. Shambhu Dongol