discussion
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
discussion [2007/11/09 02:26] – 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 379: | Line 379: | ||
- | ====== 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 575: | 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.1194575181.txt.gz · Last modified: 2007/11/09 02:26 by huiwang