Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
for some reasons, the PID was sometimes not inited correctly in Java
[simgrid.git] / src / bindings / java / org / simgrid / msg / Process.java
index 355856d..ecc7cee 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (c) 2006-2014. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2006-2017. 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. */
@@ -218,8 +217,13 @@ public abstract class Process implements Runnable {
         *
         */ 
        public int getPID()  {
+               if (pid == -1) // Don't traverse the JNI barrier if you already have the answer
+                       pid = nativeGetPID(); 
                return pid;
        }
+       // This should not be used: the PID is supposed to be initialized from the C directly when the actor is created,
+       // but this sometimes fail, so let's play nasty but safe here.
+       private native int nativeGetPID();
        /**
         * This method returns the PID of the parent of a process.
         *
@@ -281,11 +285,10 @@ public abstract class Process implements Runnable {
        /**
         * This method actually creates and run the process.
         * It is a noop if the process is already launched.
-        * @throws HostNotFoundException
         */
-       public final void start() throws HostNotFoundException {
-               if (bind == 0)
-                        create(host);
+       public final void start() {
+          if (bind == 0)
+            create(host);
        }
 
        /** This method runs the process. It calls the method function that you must overwrite. */
@@ -313,7 +316,7 @@ public abstract class Process implements Runnable {
        }
 
        /**
-        * The main function of the process (to implement).
+        * The main function of the process (to implement by the user).
         *
         * @param args
         * @throws MsgException