Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / teshsuite / java / semaphore / SemaphoreGC.java
1 /* Copyright (c) 2016. 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 semaphore;
11
12 import org.simgrid.msg.*;
13
14 class SemCreator extends Process {
15   Semaphore sem; 
16
17   SemCreator(Host h, String n){
18     super(h, n);
19   }
20
21   public void main(String[] args) throws MsgException{
22     int j; 
23     Msg.info("Creating 50 new Semaphores, yielding and triggering a GC after each");
24     for(j = 1; j <= 50; j++) {
25       sem = new Semaphore(0);
26       waitFor(10); 
27       System.gc();
28     }
29     Msg.info("It worked, we survived. The test is passed.");
30   }
31 }
32
33 public class SemaphoreGC {
34   public static void main(String[] args) throws Exception {
35     Msg.init(args);
36     if (args.length < 1) {
37       Msg.info("Usage: java -cp simgrid.jar:. semaphore.SemaphoreGC <deployment.xml>");
38       System.exit(1);
39     }
40     Msg.createEnvironment(args[0]);
41
42     Host[] hosts = Host.all();
43     new SemCreator(hosts[0], "SemCreator").start();
44
45     Msg.run();
46   }
47 }