discussion
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| discussion [2007/11/02 01:07] – huiwang | discussion [2007/11/23 13:46] (current) – franck | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| - | ====== Slawomir' | + | ===== Slawomir' |
| 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 376: | Line 376: | ||
| - | ====== 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. | ||
| - | The Cigarette-Smokers Problem. | + | |
| + | Consider a system with three smoker processes and one agent process. Each smoker continuously rolls a cigarette and then smokes it. But to roll and smoke a cigarette, the smoker needs three ingredients: | ||
| the agent on completion. The agent then puts out another two of the three ingredients, | the agent on completion. The agent then puts out another two of the three ingredients, | ||
| - | Given the exercieses | + | Given the discussions and exercises |
| <code java> | <code java> | ||
| Line 404: | Line 409: | ||
| Smoker smkr2 = new Smoker(" | Smoker smkr2 = new Smoker(" | ||
| - | // staring | + | // starting |
| agent.start(); | agent.start(); | ||
| smkr0.start(); | smkr0.start(); | ||
| Line 522: | Line 527: | ||
| while (true) | while (true) | ||
| { | { | ||
| - | int returnValue = this.table.getAndSmoke(this.id, | + | int returnValue = this.table.getAndSmoke(this.id, |
| if ( returnValue == -100) // read a end token, done | if ( returnValue == -100) // read a end token, done | ||
| break; | break; | ||
| Line 571: | Line 576: | ||
| | | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== Franck' | ||
| + | |||
| + | 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 = " | ||
| + | final int MAX = 1000; | ||
| + | final int LECTURES = 4; | ||
| + | final int NUMBER_PER_LECTURE = 4; | ||
| + | |||
| + | List< | ||
| + | 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(" | ||
| + | for (int j = 0; j < NUMBER_PER_LECTURE | ||
| + | { | ||
| + | System.out.printf(" | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| </ | </ | ||
discussion.1193965672.txt.gz · Last modified: by huiwang
