Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Previous change made this size smaller, but it resulted in actually another algorithm...
[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 import org.simgrid.msg.Process;
14 import org.simgrid.trace.Trace;
15
16 import java.util.ArrayList;
17 import java.util.List;
18 import java.util.Random;
19
20 class SemCreator extends Process {
21         Semaphore sem; 
22
23         SemCreator(Host h, String n){
24                 super(h, n);
25         }
26
27         public void main(String[] args) throws MsgException{
28                 int j; 
29                 Msg.info("Creating 50 new Semaphores, yielding and triggering a GC after each");
30                 for(j = 1; j <= 50; j++) {
31                         sem = new Semaphore(0);
32                         waitFor(10); 
33                         System.gc();
34                 }
35                 Msg.info("It worked, we survived. The test is passed.");
36         }
37 }
38
39
40 public class SemaphoreGC {
41         public static void main(String[] args) throws Exception {
42
43                 Msg.init(args);
44                 if (args.length < 1) {
45                         Msg.info("Usage: java -cp simgrid.jar:. semaphore.SemaphoreGC <deployment.xml>");
46                         System.exit(1);                 
47                 }
48                 Msg.createEnvironment(args[0]);
49
50                 Host[] hosts = Host.all();
51                 new SemCreator(hosts[0], "SemCreator").start();
52
53                 Msg.run();
54         }
55
56 }