ANNOUNCEMENTS

The following are in reverse chronological order.

Sun May 2 14:05:44 EDT 2010
The final exam will consist of problems from exams 1--5 or problems very much like the problems on those exams (changed numbers, changed classical synchronization problem, i.e., bounded buffer producers and consumers, dining philosophers, database readers and writers, unisex bathroom). Be prepared to analyze a class definition that is supposed to be a barrier but might have bug(s). There will be no terms to describe and define on the final exam. Readings in the Tanenbaum text book: Sections 2.3 (but not Pthreads) and 2.5. Readings in the electronic handouts: all of 062Concurrency.html; More on Concurrency Background Material on Threads, Monitors, Semaphores, and Message Passing; and Java Threads Tutorial through Message Passing (except Before Java 2 Platform Standard Edition 5.0). Exam question types will be definition, short answer, numerical and/or symbolic calculation, write pseudocode, read Java code or psuedocode, mentally execute multithreaded pseudocode or Java code to identify mistakes or errors. Graduate students will have an extra question or two to answer on the exam. Exams 1 and 2. Exam 3.
Exam 4.
Exam 5.
Thu Apr 29 12:51:17 EDT 2010
Grading on the last (non-)programming assignment: 100 for numbers/graphs/charts and a conclusion, 70 for numbers/graphs/charts but no conclusion provided.
Wed Apr 28 14:14:22 EDT 2010
In class, we will execute the following commands
appletviewer http://elvis.rowan.edu/~hartley/ConcProgJava/Applets/bubbleSort.html
appletviewer http://elvis.rowan.edu/~hartley/ConcProgJava/Applets/diningPhilosophers.html
appletviewer http://elvis.rowan.edu/~hartley/ConcProgJava/Applets/distributedDP.html
appletviewer http://elvis.rowan.edu/~hartley/ConcProgJava/Applets/parallelQuickSort.html
on a computer running Ubuntu. In the meantime, you can try them. The source code for these applets is available at http://elvis.rowan.edu/~hartley/ConcProgJava/Applets/index.html.
Wed Apr 28 12:39:29 EDT 2010
A request I received from the library.
A student checked out one of the reserve books, ``Modern Operating Systems,'' that is on reserve for your class. We have two copies on reserve. I was wondering if you could please ask the students in your class to return this copy so that it will be on reserve for other students.
Tue Apr 27 12:54:04 EDT 2010
I've heard from a few of you that the results of running the quick sort program with multiple cores is not showing any speed up as more cores are added with the taskset command. A possible explanation is that there are not enough tasks generated to keep the cores busy, so they spend most of their time blocked on receiving a message. The top command shows a low percentage for the CPUs if this is occurring. Try substituting the block matrix multiplication program for quick sort. Use large arrays filled with random numbers. On a quad core machine, divide the product matrix into four blocks: the block size is one half the number of rows by one half the number of columns in the product matrix. Use the taskset command to assign 1, 2, 3, and 4 cores to the program. This time, we know there are four tasks to be done.

If we had more time in the semester, a good next programming assignment would be to rework the block matrix multiplication program to be more like the quick sort queue (sometimes called a bag) of tasks: instead of starting a thread to calculate each block of the product matrix, create a queue of tasks, one for each block of the product matrix; then create a fixed number of threads equal to the number of cores being used; then have each thread take a task from the queue, fill in the block of the product matrix represented by the task, then take another task from the queue, ..., until all tasks are done.

Mon Apr 26 12:16:17 EDT 2010
Exam 5 is Tuesday, April 27, 2010. The information below is also applicable to the final exam. The readings and list of terms and concepts includes Exams 1, 2, 3, and 4, plus the following Readings in the Tanenbaum text book: Sections 2.3 (but not Pthreads) and 2.5. Readings in the electronic handouts: all of 062Concurrency.html; More on Concurrency Background Material on Threads, Monitors, Semaphores, and Message Passing; and Java Threads Tutorial through Message Passing (except Before Java 2 Platform Standard Edition 5.0). Terms and concepts:
Tue Apr 20 15:25:40 EDT 2010
Section tallies shows our final exam as Tuesday, May 4, 2010, 10:15am--12:15pm.
Tue Apr 20 14:30:59 EDT 2010
Programming assignment due Thursday, April 29, 2010. Same for all students. No coding involved! Using a quad core computer, such as one in the advanced lab, run the quickSort.java program with various input parameters and various numbers of hardware CPUs (set with the taskset command). In the program source, comment out the printing of the original numbers and the sorted numbers. Prepend the taskset command with the time command to get timing information (millisecond granularity). In another window, run the command top -d 1 (digit one after the minus d) and type the 1 (digit one) key so that you can see the utilization rates of the four individual CPUs. Plot several curves on a graph whose X-axis is the number of CPU-threads (1, 2, 3, 4) and whose Y-axis is the run time. Each curve will be the run times for sorting some fixed quantity of numbers (100, 1000, 1000000, 10000000, etc.) for some number of CPU-threads (1, 2, 3, 4). Any conclusions? The number of hardware CPUs set with taskset should be the same as the number of threads set in the input data. In the example commands below, num is the number of random numbers to sort and range is the upper bound of the random number generator.
prompt% time taskset -c 0   java QuickSort num range 1
prompt% time taskset -c 0-1 java QuickSort num range 2
prompt% time taskset -c 0-2 java QuickSort num range 3
prompt% time taskset -c 0-3 java QuickSort num range 4
Mon Apr 19 16:37:46 EDT 2010
Exam 4 has been graded. Scores are in the online grades file. Exam 5 is Tuesday, April 27, 2010.
Mon Apr 19 08:33:08 EDT 2010
Online student evaluation for this course opens Saturday, May 1, 2010, and ends Saturday, May 8, 2010. Instructions for students to access the evaluation:
  1. Go to "http://www.rowan.edu/selfservice.
  2. Click "Access Banner Services - Secure Area - login Required"
  3. Enter User ID and PIN.
  4. Click "Personal Information".
  5. Click "Answer a Survey".
  6. Click on one of the student evaluations for your classes.
  7. Complete the student evaluation.
  8. Click "Survey Complete" to submit your completed student evaluation.
  9. Repeat for other Spring 2010 classes.
Mon Apr 19 08:29:23 EDT 2010
The ``last assignment'' is due at the beginning of class, Thursday, April 29, 2010, as two separate printed (hardcopy) stapled documents. I do not carry around a stapler to class.
Mon Apr 19 08:07:28 EDT 2010
Activities for Tuesday, April 20, 2010: go over Exam 4, message passing (Section 2.3.8 of the text book) and barriers (Section 2.3.9). See also Background Material on Message Passing. We will also look at java.util.concurrent's BlockingQueue, ArrayBlockingQueue, and LinkedBlockingQueue. An example is the bounded buffer producers and consumers implemented with a blocking queue: boundedBufferQueue.java. Another example is the bounded buffer producers and consumers implemented with a message passing class javaconcprog/MessagePassing.java: boundedBufferMP.java. Activities for Thursday, April 22, 2010: shared-memory multiprocessor architectures (Section 8.1 of the text book).
Sat Apr 17 14:12:54 EDT 2010
Grades and comments on the unisex bathroom problem. A common serious error was using signal() instead of signalAll() when the last of a gender leaves the bathroom. This could leave some of the opposite gender standing outside the bathroom, stranded, instead of going in. Note that in the original readers and writers, signalAll() is used when a writer finishes to nudge all waiting readers into the database. Those who made this mistake should rerun their programs and take a close look at the output to see this stranding happening. Try five threads of each gender.
0612         70: -30 need signalAll() instead of signal(); output clearly shows that when one gender leaves, not all of other waiting gender are signaled into bathroom
0727         70: -30 need signalAll() instead of signal(); output clearly shows that when one gender leaves, not all of other waiting gender are signaled into bathroom
0964         90: -10 women must go first at the beginning of the simulation, an artificial restriction
1926         70: -30 need signalAll() instead of signal(); output clearly shows that when one gender leaves, not all of other waiting gender are signaled into bathroom
1bxgi        70: -30 need signalAll() instead of signal(); output clearly shows that when one gender leaves, not all of other waiting gender are signaled into bathroom
2070        100: code and output look good
6967          0: nothing submitted
915916420   100: code and output look good
916012483    95: -5 not necessary to signal own gender
916024501    95: -5 not necessary to signal own gender
916025375   100: code and output look good
Chessmaster  70: -30 need signalAll() instead of signal(); output clearly shows that when one gender leaves, not all of other waiting gender are signaled into bathroom
J9137        00: code and output look good but turned in late
Keelah        0: nothing submitted
Shads        70: -30 need signalAll() instead of signal(); output clearly shows that when one gender leaves, not all of other waiting gender are signaled into bathroom
Torque        0: nothing submitted
WayneBrody    0: nothing submitted
ZnyvxNuzrq  100: code and output look good
thepizza    100: code and output look good
utley       100: code and output look good
     
Thu Apr 15 11:55:11 EDT 2010
A class member found an error in the number of absences and lates recorded in the online grades file. Please check your number and report any suspected errors to me.
Wed Apr 14 10:34:25 EDT 2010
Skeleton code of the unisex bathroom (symmetric readers and writers) problem (does not include any starvation prevention). Note the symmetry and that when the last of one gender leaves the bathroom, all of the other waiting gender, if any, are signalled. Also, when the last of one gender leaves the bathroom, there is no need to signal any waiting of its own gender because there should not be any of its own gender waiting. (In the starvation prevention version, there might be some waiting but they must continue waiting to prevent starvation.)
class Bathroom {
   ...
   private void manEnter() throws InterruptedException {
      mutex.lock();
      try {
         while (numWomenIn > 0) { men.await(); }
         numMenIn++;
      } finally { mutex.unlock(); }
   }
   private void manExit() throws InterruptedException {
      mutex.lock();
      try {
         numMenIn--;
         if (numMenIn == 0 && mutex.hasWaiters(women)) women.signalAll();
      } finally { mutex.unlock(); }
   }
   private void womanEnter() throws InterruptedException {
      mutex.lock();
      try {
         while (numMenIn > 0) { women.await(); }
         numWomenIn++;
      } finally { mutex.unlock(); }
   }
   private void womanExit() throws InterruptedException {
      mutex.lock();
      try {
         numWomenIn--;
         if (numWomenIn == 0 && mutex.hasWaiters(men)) men.signalAll();
      } finally { mutex.unlock(); }
   }
   ...
}
     
Tue Apr 6 11:35:45 EDT 2010
On Thursday, we will go over Exam 3, talk about the next programming assignment, and continue looking at the concept of monitors and Java monitors. Programming assignment.
Tue Apr 6 11:32:41 EDT 2010
Exam 4 is Thursday, April 15, 2010. The readings and list of terms and concepts includes Exams 1, 2, and 3 plus the following. Readings in the Tanenbaum text book: Sections 2.3.1--2.3.7 (but not Pthreads) and 2.5. Readings in the electronic handouts: all of 062Concurrency.html; More on Concurrency Background Material on Threads, Monitors, and Semaphores; and Java Threads Tutorial through Semaphores. Terms and concepts:
Thu Apr 1 16:01:21 EDT 2010
I forgot to say in class to look for a COMMENTS.TXT file on your USB drive for an explanation of your grade if it is less than full credit.
Thu Apr 1 12:12:21 EDT 2010
The thought question below involving boundedBufferSleepWakeupFix.java will be on Exam 3 because I forgot to do it in class. Make sure you have prepared an answer and have it in your mind on Tuesday.
Thu Apr 1 11:06:18 EDT 2010
I forgot to hand back the Exam 2 papers that I still have. If you want yours before Tuesday, stop by my office today (Thursday) before 4pm. After 4pm, they will be with the departmental secretary.
Thu Apr 1 11:02:15 EDT 2010
Dining philosophers photo and movie. Right now they are forbidden access. I need to check first to see if anybody objects to being seen in these on the Internet.
Thu Apr 1 11:01:12 EDT 2010
No monitors on Exam 3 (April 6, 2010); we'll save that for the remaining exams. Semaphores and previous thread stuff and bounded buffer semaphore implementation are the topic coverage for Exam 3.
Thu Apr 1 08:55:02 EDT 2010
In class, we will look at a montor for the database readers and writers, readersWritersMonitor.java and readersWritersDriver.java, with output example readersWritersMonitor.txt.
Thu Apr 1 08:32:06 EDT 2010
Information on volatile. We talked about this situation in class and what can happen if the shared variables are not declared volatile. A thread (other than the thread making the assignments) can see y change to 4 before seeing x change to 3. 4 is possible for the final value of z if the variables are not volatile but not possible if the variables are volatile.
shared: volatile int x = 0, y = 0;

T0: { x = 3; y = 4; }

T1: { z = y; z = z + x; }

Now let's change the problem slightly.
shared: volatile int w = 0;

T0: { w = 3; w = 4; }

T1: { z = w; z = z + 2*w; }

Whether volatile or not, the JVM memory model guarantees the other threads will see the updates to the single variable w done in the order shown. All threads see w first change to 3, then change to 4. 10 is not possible for the final value of z whether the variables are volatile or not.
Wed Mar 31 18:00:11 EDT 2010
A static block that prints out the OS stuff and number of CPUs has been added to javaconcprog.AgeRandom.java. So you can now remove this Java fragment, availableProcessors.java.txt, from you code that imports javaconcprog.AgeRandom.java.
Tue Mar 30 09:00:53 EDT 2010
After handing back and going over the second exam, we will do this.
Mon Mar 29 14:13:39 EDT 2010
Exam 3 is Tuesday, April 6, 2010. The readings and list of terms and concepts includes Exams 1 and 2 plus the following. Readings in the Tanenbaum text book: Sections 2.3.1--2.3.7 (but not Pthreads) and 2.5. Readings in the electronic handouts: all of 062Concurrency.html; More on Concurrency Background Material on Threads, Monitors, and Semaphores; and Java Threads Tutorial through Semaphores. Terms and concepts:
Sun Mar 28 13:40:42 EDT 2010
This Java program, lines.java, provides a hint about how to use semaphores to make sure that a bunch of threads print their lines in a deterministic, rather than unpredictable, order.
Fri Mar 26 15:46:33 EDT 2010
For those who like their code sweetened with syntactic sugar, P(Semaphore s) and V(Semaphore s) have been added to javaconcprog.AgeRandom.java.
Thu Mar 25 13:49:14 EDT 2010
Some words on debugging printlns for the readers and writers. Instead of using a printState method, put printlns in your program that resemble the mutual exclusion driver program, mutualExclusionDriver.java, and use the age() method. I've put some in the skeleton code in the assignment statement below. Then you can eyeball the output to check the reader and writer constraints: concurrent readers but exclusive writers. In a similar manner, you can eyeball the mutual exclusion program output, mutualExclusionBakery.txt, and see that only one thread at a time is in its critical section.
Thu Mar 25 12:06:49 EDT 2010
A condensed version of the graduate students' fixed thread pool for generating prime numbers, primesFixedThreadPool.java.
Tue Mar 23 11:19:06 EDT 2010
javaconcprog.AgeRandom.java now has a seed(long) method for static import.
Mon Mar 22 15:54:21 EDT 2010
A ``write-up'' requirement has been added to the assignment due Tuesday, March 30, 2010.
Thu Mar 18 13:34:39 EDT 2010
The exam schedule for the rest of the semester is now in the syllabus. Exam 2 is Thursday, March 25, 2010. The readings and list of terms and concepts is exactly the same as Exam 1 (note atomic instruction/action was added).
Wed Mar 17 15:30:21 EDT 2010
A thought exercise has been added to the assignment due Tuesday, March 30, 2010.
Tue Mar 16 08:23:45 EDT 2010
The semaphore bounded buffer producer consumer program, boundedBufferSemaphore.java, has been modified to work with multiple producers and/or multiple consumers.
Sun Mar 14 10:41:20 EDT 2010
Check below for clarifications to the database readers and writers assignment.
Fri Mar 12 14:10:21 EST 2010
Some articles for the graduate students to file away for future reference for a possible future programming assignment. These articles are on OpenCL and CUDA. http://www.linux-mag.com/id/7725, http://www.linux-mag.com/id/7707, http://www.linux-mag.com/id/7701.
Wed Mar 10 12:00:43 EST 2010
Here is the essence of Jon's code using the synchronized keyword instead of volatile.
class BufferItem {
   private double value = 0;
   private boolean occupied = false;
   public synchronized double getValue() { return value; }
   public synchronized boolean getOccupied() { return occupied; }
   public synchronized void setValue(double v) { value = v; }
   public synchronized void setOccupied(boolean o) { occupied = o; }
}
class BoundedBuffer {
   public void deposit(double value) throws InterruptedException {
      while (buffer[putIn].getOccupied()) { ...
      ...
      buffer[putIn].setValue(value);
      buffer[putIn].setOccupied(true);
   ...
   public double fetch() throws InterruptedException {
      while (!buffer[takeOut].getOccupied()) { ...
      ...
      value = buffer[takeOut].getValue();
      buffer[takeOut].setOccupied(false);
   ...
}
   
With a minute left in the class meeting, Jon said he ran the program with five producers and one consumer (I think). If you look at the beginning of the original busy-waiting bounded buffer, the one using volatile, you will see the comment, ``Designed for a single producer thread and a single consumer thread.'' I think we discussed the reason for this in class when we looked at the original version. Does the same comment apply to Jon's synchronized version? Why or why not?

The volatile modifier is used to remove visibility races, also called data races in the Goetz book the graduate students are reading. But volatile does not eliminate race conditions, such as the lost update. The way synchronized is used in the busy-waiting bounded buffer code above also ensures visibility but does not necessarily remove race conditions. Can you think of a race condition that can occur in the busy-waiting bounded buffer code above when there are five producers? Sometimes the term check then act or put if absent is used to describe the sequence of operations vulnerable to a race condition.

Wed Mar 10 07:30:42 EST 2010
I fixed the error in twelve.java that printed each verse an incorrect number of times. I put in some sanity checks and declared as many variables final as possible, all ``good things'' you should always strive to do.
Tue Mar 9 13:10:47 EST 2010
The two mutual exclusion algorithms for an arbitrary number of threads are now linked into the electronic handouts page.
Mon Mar 8 09:37:17 EST 2010
All: Thought Exercise due in class Tuesday, March 30, 2010.
  1. Once upon a time, a concurrent programming student tried to fix the sleep/wakeup skeleton code on page 127 of the Tanenbaum text book by using a binary sempahore and arrived at the following code: boundedBufferSleepWakeupFix.java. While this code does fix the lost wakeup problem, it still has at least two serious bugs in it. Find them all.
All: Programming Assignment due in class Tuesday, March 30, 2010.
  1. Using the skeleton code in 062Concurrency.html and on page 168 of the Tanenbaum textbook, implement a Java semaphore version of the database readers and writers in Java. Use the java.util.concurrent.Semaphore class. Use the Java semaphore version of the bounded buffer producers and consumers, boundedBufferSemaphore.java and boundedBufferDriver.java, as an example for building your Database class and Driver program. The lifetime of a reader thread is
        while (true) do {
          println(age() reader x sleeping for m milliseconds);
          Thread.sleep(random number of milliseconds);
          println(age() reader x wants to read);
          wantToReadFromDatabase();
        }
    
    The lifetime of a writer thread is similar
        while (true) do {
          println(age() writer x sleeping for m milliseconds);
          Thread.sleep(random number of milliseconds);
          println(age() writer x wants to read);
          wantToWriteIntoDatabase();
        }
    
    Reading and writing in the database, once permission is granted, are simulated like this.
        readFromDatabase() {
          println(age() reader x reading for m milliseconds);
          Thread.sleep(random number of milliseconds);
          println(age() reader x done reading);
        }
        ...
        writeIntoDatabase() {
          println(age() writer x writing for m milliseconds);
          Thread.sleep(random number of milliseconds);
          println(age() writer x done writing);
        }
    
    Set up input parameters for you program
    • number of reader threads
    • numbers of writer threads
    • total running time of the simulation
    • max reader sleep outside database for random number generator
    • max writer sleep outside database for random number generator
    • max reader sleep reading database for random number generator
    • max writer sleep writing database for random number generator
    Now you can show readers starving writers with proper choice of input parameters. Include on your USB drive one or more text files containing the output of your program that clearly show
    • multiple readers can read the database simultaneously;
    • if one or more readers are reading, no writer is writing;
    • if a writer is writing, no readers are reading and no other writer is writing.
  2. Implement a monitor version of the database readers and writers. Use the classes java.util.concurrent.locks.Lock, java.util.concurrent.locks.ReentrantLock, and java.util.concurrent.locks.Condition. Use the monitor version of the bounded buffer producers and consumers, boundedBufferMonitor.java and boundedBufferDriver.java, as an example for building your Database class and Driver program. Include on your USB drive one or more text files containing the output of your program that clearly show
    • multiple readers can read the database simultaneously;
    • if one or more readers are reading, no writer is writing;
    • if a writer is writing, no readers are reading and no other writer is writing.
  3. The Java program twelve.java prints out lines from the song ``The Twelve Threads of Java'' in a random order. Use sempahores to contrain the order of printing so that the song is displayed properly, shown in twelve.txt. Do not worry about indentation. Each thread is in charge of printing one of the lines from the song and only that line. Include on your USB drive one or more text files containing the output of your program that clearly show it is working properly.
All: All programming assignments from now on, including the three above, require composing a write-up document for each programming assignment. A missing write-up will result in a 20 point penalty.
Fri Mar 5 12:03:34 EST 2010
Graduate students: Programming Assignment due in class Tuesday, March 23, 2010.
  1. Read Sections 5.5.2, 6.2, and 6.3 in the Goetz, et al, Java Concurrency in Practice book for information about the following classes and interfaces, most if not all from the java.util.concurrent package.
    • Future
    • FutureTask
    • Callable
    • Executor
    • Executors
    • Executors.newFixedThreadPool(int numThreads)
    • ExecutorService
    • CompletionService
    • ExecutorCompletionService
    • BlockingQueue
    Also look at the example on page 108 for how to use Future, FutureTask, and Callable.
  2. Following the shaded-box guideline on page 119, rewrite the parallelPrimes.java example to use the above classes and interfaces instead of new Thread(Runnable r).start(). In particular, use Executors.newFixedThreadPool(int numThreads), where numThreads is part of the input data. Each Callable computes whether or not a number is prime and returns an object that encapsulates a true/false value and the number it worked on. Use a CompletionService so that the main thread can print the results as soon as they are available. Using numThreads on the columns and number of CPUs (1, 2, 3, and 4, set with the taskset command) on the rows, create a table (or series of plots) of running times of your program on one of the quad-core machines in the Advanced Lab.
  3. Repeat for your block matrix multiplication program. In this program, the value of numThreads is determined by the number of blocks calculated from the input data (number of rows and columns in the matrices to be multiplied and block size). The Callable returns true, a dummy value, when it is done. Also try making numThreads part of the input data instead of calculated from the input data.
Thu Mar 4 13:54:53 EST 2010
An article about the programming done in today's automobiles, two URLs to the same article, http://www.businessweek.com/idg/2010-03-02/toyota-s-woes-raise-questions-about-auto-electronics.html and http://www.itworld.com/business/98588/toyotas-woes-raise-questions-about-auto-electronics. The article even has the term ``race condition'' in it!
Wed Mar 3 12:22:50 EST 2010
Stuff for Exam 1 Thursday. Readings in the Tanenbaum text book: Sections 2.2, 2.3.1--2.3.4, 2.3.6 (but not Pthreads), 2.4.6. Readings in the electronic handouts: 060Threads.html, 062Concurrency.html through Deadlock, More on Concurrency Background Material on Threads, and Java Threads Tutorial through Synchronized Blocks. No more stuff was added during the last 24 hours to the list below so the list is closed.
Tue Mar 2 08:32:27 EST 2010
Programming assignment due Tuesday, March 9, 2010. Remove the volatile modifier from the fields value and occupied in the BufferItem class in boundedBufferBusyWaiting.java. Also change the public to private. Add synchronized set and get methods for the value and occupied fields. Demonstrate that the consumer waits if the bounded buffer is empty and that the producer waits if the bounded buffer is full.
Sun Feb 28 13:44:20 EST 2010
Programming assignment due Tuesday, March 9, 2010. Describe the interleavings that lead the auditor to see too much money and too little money in the bankAccountsAuditor.java example. Use a synchronized block to fix the race condition in the program. Demonstrate with varying numbers of accounts that the race condition in the original version does not occur.
Sat Feb 27 12:57:36 EST 2010
Graduate students: read Part I (Chapters 1--5, pages 1--110) in the Goetz, et al, Java Concurrency in Practice book. This is to prepare for some programming assignments and other projects.
Thu Feb 25 11:12:15 EST 2010
My office hours will end early today depending on the snow. Send questions via e-mail.
Thu Feb 25 08:23:30 EST 2010
Rowan is officially open today so we will hold class, but because of the weather, Today, I will go over
Tue Feb 23 14:02:00 EST 2010
I've looked at the twelve USB drives handed in during class today, graded Pass/Fail. All twelve passed. I will bring the drives to class Thursday. If you need yours before then, stop by my office. Here are the essences of the strict alternation and busy-waiting flag algorithms.
class Arbitrator {
   private volatile boolean lock_flag = false; // shared boolean flag
   public void wantToEnterCS(int i) {       // pre-protocol
      while (lock_flag) { // busy wait
      }
      lock_flag = true;
   }
   public void finishedInCS(int i) {        // post-protocol
      lock_flag = false;
   }
}
class Arbitrator {
   private volatile int turn = 0;     // strict alternation
   public void wantToEnterCS(int i) {       // pre-protocol
      while (turn != i) { // busy wait
      }
   }
   public void finishedInCS(int i) {        // post-protocol
      turn = other(i);
   }
}
Fri Feb 19 12:31:21 EST 2010
The Peterson's algorithm simulation code, mutualExclusionPeterson.java and mutualExclusionDriver.java, has been javadoc commented. Grab fresh copies if you grabbed earlier.
Thu Feb 18 11:22:04 EST 2010
Exam 1 will be Thursday, March 4, 2010. Question types will be definition, short answer, numerical and/or symbolic calculation, write pseudocode, read Java code or psuedocode, mentally execute multithreaded pseudocode or Java code to identify mistakes or errors. The terms and concepts covered will appear in the announcements page as we get closer to the exam date. Graduate students will have an extra question or two to answer on the exam.
Thu Feb 18 08:13:17 EST 2010
Assignment for the Graduate students only, due in class Tuesday, March 2, 2010:
Wed Feb 17 13:05:12 EST 2010
Did I mention in class that there are two copies of the Tanenbaum OS text book on overnight (or three day, I forget) reserve at the Rowan library? Or are you just finding out about this now?
Wed Feb 17 12:37:55 EST 2010
Read the subsection ``Background Material on Threads'' contained in More on Concurrency. Read through the section ``Synchronized Blocks'' contained in Java threads tutorial.
Tue Feb 16 15:43:35 EST 2010
Why didn't anybody tell me that the machines in the Advanced Lab are quad core? At least the random machine I walked up to is. This is very useful information to know for programming assignments. And why is it that the student lab has better machines than the faculty have?
Tue Feb 16 12:54:41 EST 2010
Today's white board photos, thanks to Spence: whiteboard20100216.html. Overlapping images, courtesy of Adam Michalsky: whiteboardOverlapping.html.
Thu Feb 11 17:50:37 EST 2010
Here is the essence of the block matrix multiplication algorithm based on Rob's code shown in class, which seemed intuitive and straightforward.
private void multiply(int[][] a, int[][] b, int[][] c, int p, int q) {

   LinkedList workers = new LinkedList();

   for (int aStart = 0; aStart < a.length; aStart += p) {
      for (int bStart = 0; bStart < b[0].length; bStart += q) {
         Thread multiply = new Thread(
            new MultiplyWorker(a, b, c, p, q, aStart, bStart)
         );
         workers.add(multiply);
         multiply.start();
      }
   }
}

public class MultiplyWorker implements Runnable {

   public void run() {
      for (int i = aStart; i < aStart + p; i++) {
         for (int j = bStart; j < bStart + q; j++) {
            for (int k = 0; k < b.length; k++) {
               c[i][j] += a[i][k] * b[k][j];
            }
         }
      }
   }
}
Wed Feb 10 17:18:16 EST 2010
Assignments.
  1. Due date Tuesday, February 16, 2010. In how many different ways can m instructions from thread A be interleaved with n instructions from thread B where each thread's instructions stay in order?
  2. Thought problems.
    • All students. Due date Tuesday, February 16, 2010. Suppose two threads share the following three variables.
      int x = 0, y = 0, z = 0;
      
      Suppose that one thread executes the statements
      y = 1;
      z = 2;
      
      and the other thread executes the statement
      x = y + z;
      
      What are ALL possible resulting values for the variable x? Assume that each thread is executing on its own CPU. Consider all possible interleavings and assume that we are dealing with a RISC-like load-store architecture: the only machine instructions that reference memory are register load and register store. Explain your answers!
    • Graduate students only. Due date Thursday, February 18, 2010. Suppose two threads share the following variable.
      int sum = 0;
      
      Suppose that one thread executes the loop
      for (int i = 0; i < 100; i++) {
         sum = sum + 1;
      }
      
      and the other thread executes an identical loop.
      1. Show an interleaving of the two threads that results in 200 as the final value of sum.
      2. Show an interleaving of the two threads that results in 100 as the final value of sum.
      3. Is there an interleaving that results in 2 (two) as the final value of sum? If so, show it. If not, explain why not.
      Assume that each thread is executing on its own CPU. Consider all possible interleavings and assume that we are dealing with a RISC-like load-store architecture: the only machine instructions that reference memory are register load and register store. Explain your answers!
  3. Due date Tuesday, February 23, 2010. In mutualExclusionPeterson.java, change Peterson's algorithm into the strict alternation algorithm. Use mutualExclusionDriver.java to run the program, similar to what is shown in mutualExclusionPeterson.txt. To compile and execute the program, you will have to create a subfolder javaconcprog in the folder containing your Java code. Into the subfolder javaconcprog, put a copy of AgeRandom.java.
  4. Due date Tuesday, February 23, 2010. Change strict alternation to the busy-waiting shared boolean flag version that we know does not work. But can you get it to fail in a simulation?
                shared boolean lock_flag = false;
    mutex_begin() {                             mutex_end() {
      while (lock_flag) {                         lock_flag = false;
        /* continue */ ;                            }
      }
      lock_flag = true;
    }
    
Wed Feb 10 15:17:56 EST 2010
Rowan will be closed Thursday. Watch this space for some assignments to give you something to do while cooped up inside.

Rob, on your quad core machine, can you make some runs with various block sizes using 1, 2, 3, and 4 CPUs? I think the commands are like this.

prompt% taskset -c 0 java Driver
prompt% taskset -c 0-1 java Driver
prompt% taskset -c 0-2 java Driver
prompt% taskset -c 0-3 java Driver
Tue Feb 9 13:50:12 EST 2010
Search engines are wonderful! I found some articles, http://www.velocityreviews.com/forums/t667701-setting-the-cpu-affinity-for-a-whole-jvm-on-linux.html and http://www.cyberciti.biz/tips/setting-processor-affinity-certain-task-or-process.html, that show how to limit the number of CPUs used by the threads in a Java program. I haven't tried it out yet; that is next....yup, it works on a dual core.
Tue Feb 9 12:49:37 EST 2010
Documentation on command line arguments to the java command are available at http://java.sun.com/javase/6/docs/technotes/tools/solaris/java.html for Solaris/Linux and http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html for Windows. Here is another page of virtual machine options, http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp. So far, I have found nothing to control the number of CPUs used by the threads in the JVM.
Thu Feb 4 07:30:01 EST 2010
3pm today is the cutoff for 100 points for the office visit. I have a meeting today from 11:30am to around noon and another meeting today from 1:35pm to around 2:30pm. I will not be in my office during those times. Possible snow storm Tuesday, the matrix multiplication due date/time. Watch this page for a class cancellation notice.
Tue Feb 2 08:01:07 EST 2010
Malik told me about a program from http://www.linuxliveusb.com/ that runs on Windows and creates a bootable Linux USB drive. Thanks, Malik! This is useful for those people whose computers boot into Windows when turned on. People who have no computers that run Windows can use the technique I will show in class (or they can go into a Rowan public lab).
Sat Jan 30 10:55:40 EST 2010
Since we are now meeting in a room full of computers, I don't want them to go to waste. Of course, I know that left to your own devices, they will certainly not go to waste, but you know what I mean. I am going to try to show in class how to create a bootable-into-Ubuntu USB drive on which you can read, write, and save your own files and also install the Java development kit. For this you will need a USB drive of at least two GB. It will be reformatted during the process so if it is not empty, whatever is on it will be lost. You will need an Ubuntu Live CD (from ubuntu.com) and the Sun Java development kit (from java.sun.com). The (approximate) steps I will show in class are
  1. Boot the Ubuntu Live CD.
  2. Download the Sun JDK and save.
  3. In System | Administration, select USB Startup Disk Creator.
  4. In the upper half of the dialog box, pick the CD drive for the location.
  5. In the lower half of the dialog box, pick /dev/sdb1 and click format.
  6. Move the slider to 1 GB for the size of reserved extra space.
  7. Click Make Startup Disk.
  8. After the startup USB drive has been created, copy the Sun JDK to it.
  9. Change directories to the USB drive where you just copied the JDK file and make it executable with the chmod command.
  10. Reboot the computer, making sure to hit the correct function key to select the boot device.
  11. Choose to boot from the USB drive and wait....
  12. Open a terminal window from Applications | Accessories.
  13. Enter the command /cdrom/jdk-6u18-linux-i586.bin to install the JDK in your home directory.
  14. In your home directory, edit the file .bash_aliases to contain the two lines
    export JAVA_HOME=$HOME/jdk1.6.0_18
    export PATH=$JAVA_HOME/bin:$PATH
                
  15. Close the terminal window and open it again.
  16. Enter the command java -version to make sure it is working.
Fri Jan 29 10:59:41 EST 2010
Example http://elvis.rowan.edu/~hartley/Courses/IOOP/Programs/widgets.java of self-checking automated tests of a simple class. Hospital example http://elvis.rowan.edu/~hartley/Courses/IOOP/Programs/hospital.java of self-checking automated tests in a program involving inheritance. Regression testing examples, invoicing system http://elvis.rowan.edu/~hartley/Courses/OOPDA/Programs/Invoicing/index.htm and car rental system http://elvis.rowan.edu/~hartley/Courses/OOPDA/Programs/CarRentals/index.htm.
Thu Jan 28 14:19:17 EST 2010
Insert this Java fragment, availableProcessors.java.txt, into your code to see how many CPUs are available for the threads in your Java program.
Thu Jan 28 10:57:15 EST 2010
First programming assignment, due in class 9:25 am, Tuesday, February 9, 2010: more efficient matrix multiplication. I'm sure there are hundreds, if not thousands, of block matrix multiplication Java programs out there on the Internet. If you base your program on one, you must put the URL(s) in the javadoc comments in your program. It is fine to work semi-together in the advanced lab or elsewhere, but each student must have his or her own version of the program.

Everybody must be ready to turn in a USB drive containing their program and a text file containing the output of several test runs, although it is not certain that I will collect the USB drives. Guaranteed, though, is that I will call on one or two undergrads at random and one or two grad students at random to come to the front of the room and demo their program. A detailed explanation and running commentary will be sought from those students so you better know your program inside and out!

Thu Jan 21 11:14:24 EST 2010
While reading Sections 2.3 and 2.5 of the text book and the electronic handouts 062Concurrency.html and More on Concurrency, take note of the following terms and concepts.
Wed Jan 20 15:21:11 EST 2010
CS 07.595 graduate students: I sent you e-mail about setting up a day and time during the week when we could meet separately if we have to. Please respond.
Wed Jan 20 12:59:11 EST 2010
While reviewing Sections 1.3, 2.2, and 2.4.6 of the text book and the electronic handouts 020Hardware.html, 040Multiprogramming.html, and 060Threads.html, take note of the following terms and concepts relevant to threads and concurrent programming.
Tue Jan 19 14:24:34 EST 2010
Two students showed me after class their tablet computers and how they are used for note taking by rotating the screen and laying it down over the keyboard, then using a stylus to write on the screen, like writing on a piece of electronic paper. Tablets can be used like this for note taking but not for surfing the Internet during a "closed laptop" day.
Tue Jan 19 11:02:07 EST 2010
On a fully up-to-date Ubuntu 9.10 system the Java version is
% java -version
java version "1.6.0_16"
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Server VM (build 14.2-b01, mixed mode)
    
On a fully up-to-date Ubuntu 8.04 LTS system the Java version is
% java -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) Server VM (build 14.3-b01, mixed mode)
    
If your computer differs, run the Synaptic Package Manager to Mark All Upgrades as described below.
Tue Jan 19 10:55:55 EST 2010
There are two copies of the Tanenbaum OS text book on reserve in the library.
Thu Jan 14 09:45:45 EST 2010
Ubuntu User Days is coming up the week of January 23, 2010, https://wiki.ubuntu.com/UserDays.
Wed Jan 6 14:17:00 EST 2010
First assignment (I already e-mailed this to you).
Wed Jan 6 14:05:45 EST 2010
By our class meeting on Tuesday, January 26, 2010, all registered students must have completed the following. Unprepared students will be charged a half day of attendance as described in the syllabus.
Wed Jan 6 14:05:13 EST 2010
Welcome to Concurrent Programming!


home page: http://elvis.rowan.edu/~hartley/index.html
e-mail: hartley@elvis.rowan.edu