Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Java package names should not be uppercased
[simgrid.git] / teshsuite / java / semaphoreGC / SemaphoreGC.java
1 /* Copyright (c) 2016-2017. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 /* This test ensures that the used semaphores are not garbage-collected while we still use it.
7  * This was reported as bug #19893 on gforge.
8  */
9
10 package semaphoreGC;
11
12 import org.simgrid.msg.*;
13 import org.simgrid.msg.Process;
14
15 class SemCreator extends Process {
16   Semaphore sem; 
17
18   SemCreator(Host h, String n){
19     super(h, n);
20   }
21
22   public void main(String[] args) throws MsgException{
23     int j; 
24     Msg.info("Creating 50 new Semaphores, yielding and triggering a GC after each");
25     for(j = 1; j <= 50; j++) {
26       sem = new Semaphore(0);
27       waitFor(10);
28       System.gc();
29     }
30     Msg.info("It worked, we survived. The test is passed.");
31   }
32 }
33
34 public class SemaphoreGC {
35   private SemaphoreGC() {
36     throw new IllegalAccessError("Utility class");
37   }
38
39   public static void main(String[] args) throws Exception {
40     Msg.init(args);
41     if (args.length < 1) {
42       Msg.info("Usage: java -cp simgrid.jar:. semaphoreGC.SemaphoreGC <deployment.xml>");
43       System.exit(1);
44     }
45     Msg.createEnvironment(args[0]);
46
47     new SemCreator(Host.getByName("Fafard"), "SemCreator").start();
48
49     Msg.run();
50   }
51 }