Yes you do have to program it first.
Answer:
Explanation:
Following are the Semaphores:
Customers: Counts waiting customers;
Barbers: Number of idle barbers (0 or 1)
mutex: Used for mutual exclusion.
Cutting: Ensures that the barber won’t cut another customer’s hair before the previous customer leaves
Shared data variable:
count_cust: Counts waiting customers. ------------copy of customers. As value of semaphores can’t access directly.
// shared data
semaphore customers = 0; semaphore barbers = 0; semaphore cutting = 0; semaphore mutex = 1;
int count_cust= 0;
void barber() {
while(true) { //shop is always open
wait(customers); //sleep when there are no waiting customers
wait(mutex); //mutex for accessing customers1
count_cust= count_cust-1; //customer left
signal(barbers);
signal(mutex);
cut_hair();
}
}
void customer() {
wait(mutex); //mutex for accessing count_cust
if (count_cust< n) {
count_cust= count_cust+1; //new customer
signal(customers); signal(mutex);
wait(barbers); //wait for available barbers get_haircut();
}
else { //do nothing (leave) when all chairs are used. signal(mutex);
}
}
cut_hair(){ waiting(cutting);
}
get_haircut(){
get hair cut for some time; signal(cutting);
}
Answer:
public static void PrintShampooInstructions(int numberOfCycles){
if (numberOfCycles<1){
System.out.println("Too Few");
}
else if(numberOfCycles>4){
System.out.println("Too many");
}
else
for(int i = 1; i<=numberOfCycles; i++){
System.out.println(i +": Lather and rinse");
}
System.out.println("Done");
}
Explanation:
I have used Java Programming language to solve this
Use if...elseif and else statement to determine and print "Too Few" or "Too Many".
If within range use a for loop to print the number of times
<span> Directions that tells an operating system's dispatcher what to do when a process's time slice is over.Wait for the interrupt handler to be execute. Allow the scheduler to update the process table. Select the process form the process table that has the highest priority, restart the time, and allow the selected process to begin its time slice. Directions that tells an operating system's dispatcher what to do when a process's time slice is over. Signal an interrupt, save the current position, execute the current position, execute the interrupt handler, and switch to the next process until the process or processes is complete. If a process executes an I/O request, the time slice of that process will be terminated because it would waste the remaining time waiting for the controller to perform the request. A situation in a time-sharing system in which a process does not consume the entire time slice allotted to it. Client/server model Defines the basic roles played by the processes as being that of either a client, which makes requests of other processes Components of the email address </span>