cs205: engineering software?
20 September 2010

Quiz 4

Name: _________________________________________________________

Collaboration Policy — Work alone without using any notes or other materials.

1. Why is it unsafe to stop a running thread? (Give at least 2 reasons.)

2. Why would the Java reference monitor fail to provide the necessary protection if the bytecode verifier did not provide control flow safety correctly?

3. Which of these components are part of the trusted computing base when a user runs a Java applet in a web page? Components: applet source code, applet class file, Java compiler, Java bytecode verifier, Java VM. (Circle the components that are part of the trusted computing base.)

4. What bytes are at the beginning of every Java class file?

5. Explain what the checkcast instruction does?

6. Explain why the revised Philosopher code from PS5 (shown below) could still deadlock becase of a race condition. (Hint: its a good idea to read the problem set comments.)
public class Philosopher {
   private Philosopher colleague;
   private String name;
   private String quote;

   public Philosopher(String name, String quote) {
      this.name = name;
      this.quote = quote;

   public synchronized void setColleague(Philosopher p) {
      colleague = p;

   public synchronized void argue() { ... } // elided

   public void philosophize () {
      Object lock1, lock2;

      if (colleague != null) { // Need a colleague to start and argument.
         // Always grab the lock for whichever name is alphabetically first
         if (name.compareTo (colleague.name) < 0) {
            lock1 = this;
            lock2 = colleague;
         } else {
            lock1 = colleague;
            lock2 = this;
         synchronized (lock1) {
            synchronized (lock2) {
                 System.err.println (name + "[Thread " 
                      + Thread.currentThread().getName () + "] says " + quote);
                 colleague.argue ();

These questions are not graded, but your answers are appreciated and will help design the rest of the course.

7. What is one question that should be asked on the team assesment form for the project?

8. What concepts had you hoped to see in cs205 have not been covered yet?

9. In the eight remaining classes, which of these topics would you be most interested in? (rank order as many as you want, with 1 as the most preferred topic)

_____ Other: _________________________________
_____ Other: _________________________________
_____ Extreme Programming
_____ Design Patterns
_____ Reflection
_____ Performance Optimization
_____ Memory Management (Garbage Collection)
_____ Class Loading
_____ Distributed Programming
_____ Cryptography
_____ C# and .Net
_____ Different Programming Languages
_____ Web Programming
_____ Software Life Cycle
_____ Famous Software Disasters