Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines with new year.
[simgrid.git] / teshsuite / java / semaphoregc / SemaphoreGC.java
1 /* Copyright (c) 2016-2020. 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   SemCreator(Host h, String n){
17     super(h, n);
18   }
19
20   public void main(String[] args) throws MsgException{
21     int j;
22     Msg.info("Creating 50 new Semaphores, yielding and triggering a GC after each");
23     for(j = 1; j <= 50; j++) {
24       new Semaphore(0);
25       waitFor(10);
26       System.gc();
27     }
28     Msg.info("It worked, we survived. The test is passed.");
29   }
30 }
31
32 public class SemaphoreGC {
33   private SemaphoreGC() {
34     throw new IllegalAccessError("Utility class");
35   }
36
37   public static void main(String[] args) throws Exception {
38     Msg.init(args);
39     if (args.length < 1) {
40       Msg.info("Usage: java -cp simgrid.jar:. semaphoregc.SemaphoreGC <deployment.xml>");
41       System.exit(1);
42     }
43     Msg.createEnvironment(args[0]);
44
45     new SemCreator(Host.getByName("Fafard"), "SemCreator").start();
46
47     Msg.run();
48   }
49 }