examples/java/app/masterworker/java_app_masterworker_compiled
examples/java/app/pingpong/java_app_pingpong_compiled
examples/java/app/tokenring/java_app_tokenring_compiled
+examples/java/async/yield/java_async_yield_compiled
examples/java/async/dsend/java_async_dsend_compiled
examples/java/async/waitall/java_async_waitall_compiled
examples/java/dht/chord/java_dht_chord_compiled
set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/async/waitall)
set(async_waitall_sources ${srcdir}/Main.java ${srcdir}/Receiver.java ${srcdir}/Sender.java)
+set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/async/yield)
+set(async_yield_sources ${srcdir}/Main.java ${srcdir}/Yielder.java)
+
set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/async/dsend)
set(async_dsend_sources ${srcdir}/Main.java ${srcdir}/Receiver.java ${srcdir}/Sender.java)
set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/task/priority)
set(task_priority_sources ${srcdir}/Main.java ${srcdir}/Test.java)
-foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong app_tokenring async_waitall async_dsend
+foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong app_tokenring async_yield async_waitall async_dsend
cloud_migration cloud_masterworker dht_chord dht_kademlia energy_consumption energy_pstate energy_vm io_file io_storage
process_kill process_migration process_startkilltime process_suspend task_priority trace_pingpong)
string (REPLACE "_" "/" example_dir ${example})
${CMAKE_CURRENT_SOURCE_DIR}/task/priority/priority.xml PARENT_SCOPE)
if(enable_java)
- foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong app_tokenring async_waitall async_dsend
+ foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong app_tokenring async_yield async_waitall async_dsend
cloud_migration cloud_masterworker dht_chord dht_kademlia energy_consumption energy_pstate energy_vm io_file io_storage
process_kill process_migration process_startkilltime process_suspend task_priority trace_pingpong)
string (REPLACE "_" "/" example_dir ${example})
--- /dev/null
+/* Copyright (c) 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. */
+
+package async.yield;
+
+/** This example demonstrates the use of the Task.dsend() method.
+ *
+ * This way, the sender can be detached from the communication: it is not blocked as with Task.send()
+ * and has nothing to do at the end as with Task.isend() where it must do a Comm.wait().
+ */
+
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.Host;
+import org.simgrid.msg.NativeException;
+import org.simgrid.msg.HostNotFoundException;
+
+class Main {
+ private Main() {
+ /* This is just to ensure that nobody creates an instance of this singleton */
+ throw new IllegalAccessError("Utility class");
+ }
+
+ public static void main(String[] args) throws NativeException, HostNotFoundException {
+ Msg.init(args);
+
+ String platform = "../platforms/small_platform.xml";
+ if (args.length >= 1) {
+ platform = args[0]; // Override the default value if passed on the command line
+ }
+
+ /* construct the platform and deploy the application */
+ Msg.createEnvironment(platform);
+ Host[] hosts = Host.all();
+ new Yielder(hosts[0],"Yielder", new String[] {"10"}).start();
+ new Yielder(hosts[1],"Yielder", new String[] {"15"}).start();
+
+ /* execute the simulation. */
+ Msg.run();
+ }
+}
--- /dev/null
+/* Copyright (c) 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. */
+
+package async.yield;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.Host;
+import org.simgrid.msg.Task;
+import org.simgrid.msg.Process;
+import org.simgrid.msg.HostFailureException;
+import org.simgrid.msg.TimeoutException;
+import org.simgrid.msg.TransferFailureException;
+
+public class Yielder extends Process {
+ public Yielder (Host host, String name, String[] args) {
+ super(host, name, args);
+ }
+
+ @Override
+ public void main(String[] args) {
+ int yieldsCount = Integer.parseInt(args[0]);
+ for (int i=0; i<yieldsCount; i++)
+ yield();
+ Msg.info("Yielded "+yieldsCount+". Good bye now!");
+ }
+}
\ No newline at end of file
--- /dev/null
+#! tesh
+
+! timeout 30
+$ java -classpath ${classpath:=.} async/yield/Main ${srcdir:=.}/../platforms/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [ 0.000000] (0:maestro@) Using regular java threads.
+> [ 0.000000] (1:Yielder@Boivin) Yielded 10. Good bye now!
+> [ 0.000000] (2:Yielder@Bourassa) Yielded 15. Good bye now!
+> [ 0.000000] (0:maestro@) MSG_main finished; Cleaning up the simulation...
env->SetObjectField(jprocess, jprocess_field_Process_host, jhost);
}
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_yield(JNIEnv* env, jclass cls)
+{
+ MSG_process_yield();
+}
+
JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_setKillTime (JNIEnv *env , jobject jprocess, jdouble jkilltime) {
msg_process_t process = jprocess_to_native_process(jprocess, env);
MSG_process_set_kill_time(process, (double)jkilltime);
*/
JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_migrate (JNIEnv *, jobject, jobject);
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_yield(JNIEnv* env, jclass cls);
/*
* Class org_simgrid_msg_Process
* Method setKillTime
*/
public native boolean isSuspended();
+ /** Yield the current process. All other processes that are ready at the same timestamp will be executed first */
+ public native static void yield();
+
/**
* Specify whether the process should restart when its host restarts after a failure
*