Solved

Barber Problem

Posted on 1998-08-28
3
852 Views
Last Modified: 2009-12-02
I have to implement a solution to the sleeping barber problem using semaphores in Nachos.

The problem I have is that I dont know how to implement an unknown number of semphores in c++. Because the user inputs the number of customers for the barber. And I have to fork that number of threads.
Thanks for all ur help
0
Comment
Question by:pranu
  • 2
3 Comments
 

Author Comment

by:pranu
ID: 1171539
Edited text of question
0
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1171540
The semaphores will have to be dynamically alocated with "new".  You can allocate a single array of them if you "learn" the number of customers at the start of the program.  Or if the number of customers constantly changes, you can create a linked list or other container to store them.

Let me knoe if you have questions.  
0
 

Author Comment

by:pranu
ID: 1171541
Thanks....I will implement it using the array method...just have to figure out the actual coding..cos I just started learning C++ for this course.

Thanks a lot
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now