User Tools

Site Tools


discussion

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
discussion [2007/11/02 01:13] huiwangdiscussion [2007/11/23 13:46] (current) franck
Line 5: Line 5:
  
  
-====== Slawomir's Sleeping Barber ======+===== Slawomir's Sleeping Barber =====
  
  
Line 137: Line 137:
  
  
-====== Sleeping Barber using Semaphore======+===== Sleeping Barber using Semaphore=====
  
 Since we have just covered semaphore in the class, here is a solution to the Sleeping Barber problem using semaphores. Althought it may looks awkward using semaphores in this problem,  Since we have just covered semaphore in the class, here is a solution to the Sleeping Barber problem using semaphores. Althought it may looks awkward using semaphores in this problem, 
Line 378: Line 378:
  
  
-====== Cigarette-Smokers problem ======+ 
 + 
 +===== Cigarette-Smokers problem =====
 Cigarette-Smokers problem is another famous thread synchronization problem in computer science. Cigarette-Smokers problem is another famous thread synchronization problem in computer science.
  
Line 407: Line 409:
       Smoker smkr2 = new Smoker("S-match", table ,Table.Matches);       Smoker smkr2 = new Smoker("S-match", table ,Table.Matches);
            
-      // staring the threads+      // starting the threads
       agent.start();       agent.start();
       smkr0.start();        smkr0.start(); 
Line 525: Line 527:
       while (true)        while (true) 
       {       {
-         int returnValue = this.table.getAndSmoke(this.id, this.myHave);  +         int returnValue = this.table.getAndSmoke(this.id, this.myHave);  // may or may not succeed
          if ( returnValue == -100)  // read a end token, done          if ( returnValue == -100)  // read a end token, done
             break;             break;
Line 574: Line 576:
   // end of agent    // end of agent 
  
 +</code>
 +
 +
 +===== Franck's presentation scheduler =====
 +
 +Below you find the code that I used to schedule the third presentations.
 +
 +<code java>
 +import java.util.*;
 +import java.io.*;
 +
 +/**
 + * Prints out the schedule of the third presentations.
 + *
 + * @author Franck van Breugel
 + */
 +public class Presentation
 +{
 + /**
 +  * Prints out the schedule of the third presentations.
 +  *
 +  * @param args none.
 +  * @throws Exception if file cannot be found.
 +  */
 +  public static void main(String[] args) throws Exception
 +  {
 +    final int NUMBER_OF_STUDENTS = 16;
 +    final String FILE_NAME = "COSC6490AA";
 +    final int MAX = 1000;
 +    final int LECTURES = 4;
 +    final int NUMBER_PER_LECTURE = 4;
 +
 +    List<String> names = new ArrayList(NUMBER_OF_STUDENTS);
 +    Scanner input = new Scanner(new File(FILE_NAME));
 +    while (input.hasNext())
 +    {
 +      String[] record = input.nextLine().split(",");;
 +      names.add(record[1].trim() + " " + record[0].trim());
 +    }
 +
 +    Random random = new Random();
 +    int number = random.nextInt(MAX);
 +    for (int i = 0; i < number; i++)
 +    {
 +      Collections.shuffle(names);
 +    }
 +
 +    for (int i = 0; i < LECTURES; i++)
 +    {
 +      System.out.println("^ Slot ^ Student ^");
 +      for (int j = 0; j < NUMBER_PER_LECTURE  ; j++)
 +      {
 +        System.out.printf("| %d    | %s | %n", j + 1, names.remove(0));
 +      }
 +    }
 +  }
 +}
 </code> </code>
  
discussion.1193965992.txt.gz · Last modified: 2007/11/02 01:13 by huiwang

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki