X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/3af15ddde74b1f2e6d0f78102c48271259c3c178..cdd4b1f204288924e187d305a8c2d1739040c513:/teshsuite/java/semaphore/SemaphoreGC.java diff --git a/teshsuite/java/semaphore/SemaphoreGC.java b/teshsuite/java/semaphore/SemaphoreGC.java new file mode 100644 index 0000000000..224108a3db --- /dev/null +++ b/teshsuite/java/semaphore/SemaphoreGC.java @@ -0,0 +1,56 @@ +/* Copyright (c) 2016. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +/* This test ensures that the used semaphores are not garbage-collected while we still use it. + * This was reported as bug #... on gforge. + */ + +package semaphore; + +import org.simgrid.msg.*; +import org.simgrid.msg.Process; +import org.simgrid.trace.Trace; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +class SemCreator extends Process { + Semaphore sem; + + SemCreator(Host h, String n){ + super(h, n); + } + + public void main(String[] args) throws MsgException{ + int j; + Msg.info("Creating 150 new Semaphores, yielding and triggering a GC after each"); + for(j = 1; j <= 150; j++) { + sem = new Semaphore(0); + waitFor(10); + System.gc(); + } + Msg.info("It worked, we survived. The test is passed."); + } +} + + +public class SemaphoreGC { + public static void main(String[] args) throws Exception { + + Msg.init(args); + if (args.length < 1) { + Msg.info("Usage: java -cp simgrid.jar:. semaphore.SemaphoreGC "); + System.exit(1); + } + Msg.createEnvironment(args[0]); + + Host[] hosts = Host.all(); + new SemCreator(hosts[0], "SemCreator").start(); + + Msg.run(); + } + +}