In this lab you will have the opportunity to try out for yourself some
of the synchronization techniques that we have studied in class in the
last week. Some of the work will be done on the computer
science department's UNIX compute server (csdev01) while some will be
done in Java and therefore could be written anywhere. Just make sure to
test your program on csdev01 before submitting it.
Your operating environment
You will be working on csdev01, the computer science computer server
running Linux. In class you will each be given a one semester
username for csdev01.
Logging in - Connecting to the system
Your first lab task is to log in to your
csdev01 computer account. Your csdev01 account is for the computer
science server only. This account is separate from your regular BSC
Your instructor will give you your csdev01 account user name. These
usernames are autogenerated based on the class you are taking.
for details logging into csdev01. You may need to
Now use ssh to log in. ssh is the
“secure shell”. It is much more secure than telnet and will give
some nice features that we will use later in the class.
Ssh is available built in on Macs and Linux/Unix
computers. For windows users there is a free program called putty
you can download and install to give you ssh capability. (see http://www.chiark.greenend.org.uk/~sgtatham/putty/
for the putty home page.)
now log into csdev01.
ssh -X <usename>@csdev01.bridgew.edu (where you must
replace <username> with your actual eagle username)
Note the -X (that's a capital X) this tells the computer that you
want to use "x forwarding" (put the graphical windows on the machine
front of you thank-you very much)
Many of you have used unix systems before and are now ready to go. I
suggest using emacs to edit your code.
before you begin to program:
Make a new folder called <your first name><last name>lab1
inside of your home folder. (we have two people with the same first name
and two with the same last name so both names) You can do that using the
now go into that folder (make it your working directory)
Do all of your work inside of your lab1 folder (so you will have to move
into it everytime you login to csdev01)
If you have used csdev01 and unix in your previous classes, feel free to
go on to the exercizes and get to it. If you have not used it before,
use your favorate site to learn more.
(Inspired by the complaints about how difficult it is to park on
Write a multithreaded program, using the
pthreads library, that solves the following problem with no deadlocks
and no race conditions.
At a particular college, there are two admissions counselors, and five
parking spots near the admissions office for visitors. There are 100
prospective students driving around trying to park and perform their
admissions interview. When a prospective student sees a parking
spot, he/she (generic he from now on as your book uses) pull into the
spot, wait to be advised and then leave(freeing a parking lot space for
one of the ones driving around). The advisors will advise a prospective
student and then select one of the remaining students in the parking
lot to advise next. If there are no prospective students in the
parking lot, the tired advisor snoozes at his desk.
You will need your program to start 100 "prospective student" threads
and two councilor threads. Each thread should print a message when it
is created. Students should print when they get parking spaces and when
they are advised.
When compiling, compile using the -lpthread flag. So for example, if
you wrote the program as a c++ program in a file called problem1.cpp
you might use
g++ -g -lpthread problem1.cpp -o problem1
this will invoke the compiler with debugging output (-g), linking using
the thread library (-lpthread), compile the file and link it into an
executable, and call the resulting program problem1 (-o problem1)
For this lab refer to the following websites for more information on
the many resources available from the pthread library. You may use any
of the code from these sites in your programs without any problem or
violation of the academic integraty constraints of this class. Any
other code from other websites must be referenced and if the other code
is too much of your project, your grade will be reduced. Code that has
been taken from another source that is not referenced will be a
violation of the academic integraty policy and will be treated
complete pthread tutorial from the us government
tutorial with lots of sample code
Be a little careful with the code above. It was written for a
particular compiler which seems to be more forgiving than the one we
use. The first example works great, but the second example needs a
void* as the argument to the thread function before it will compile.
Write solution to solve the currently very un-PC"cigarette smokers
problem" in java using
Java threads, and monitors (using the "synchronized" keyword) (If it
bothers your PC sensibilities, think of it at the Pot-smokers problem
and then it is all proper again.
The cigarette smokers problem
Consider a simulation with three smoker
threads and one agent
Each smoker continuously makes a cigarette and smokes it.
But to make a cigarette, a smoker needs three ingredients:
tobacco, paper, and matches.
One of the smoker threads has only paper,
another has only tobacco, and the third has only matches.
The agent thread has an infinite supply of all three materials.
The three smoker threads are initially blocked.
The agent places two randomly chosen (different) ingredients on the
unblocks the one smoker who has the remaining ingredient.
The agent then blocks.
The unblocked smoker removes the two ingredients
from the table, makes a cigarette, and smokes
it for a random amount of time, unblocking the agent on completion
of smoking the cigarette.
The agent then puts out another random two of the three ingredients,
and the cycle repeats.
In addition to the solutions to your programs above, you need to write
a readme.txt file that will be in the same lab1 folder. It should
- Your name
- A brief guide explaining how to compile your program (including
the actual compile command) and how to run it
line arguments, if any)
- A description of your solution to these two problems, including
what you did to solve the problem, and why you did it that way
- A description of what problems still exist, what doesn't quite
work right and so on.
When your readme is done and you are ready to submit move to the parent
will take you to the parent folder. And zip up the entire folder into a
zip -r <firstname><lastName>Lab1.zip lab1
Where you replace <lastName> with your own last name.
so I would write zip -r JohnSantoreLab1.zip JohnSantorelab1
The '-r' part tells zip to include everything that is in the lab1
folder as part of the zip file (the default is just a single item goes
into the zip file.
fire up konqueror and navigate to moodle.bridgew.edu and submit via
Due: 11:55pm Wednesday Oct 10th.