/** The guy we will move from host to host. It move alone and then is moved by policeman back */ static int emigrant(int argc, char *argv[]) { msg_task_t task; XBT_INFO ("I'll look for a new job on another machine where the grass is greener."); MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Boivin")); XBT_INFO("Yeah, found something to do"); task = MSG_task_create("job", 98095000, 0, NULL); MSG_task_execute(task); MSG_task_destroy(task); MSG_process_sleep(2); XBT_INFO("Moving back home after work"); MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Jacquelin")); MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Boivin")); MSG_process_sleep(4); xbt_mutex_acquire(mutex); process_to_migrate = MSG_process_self(); xbt_cond_broadcast(cond); xbt_mutex_release(mutex); MSG_process_suspend(MSG_process_self()); msg_host_t h = MSG_process_get_host(MSG_process_self()); XBT_INFO("I've been moved on this new host: %s", MSG_host_get_name(h)); XBT_INFO("Uh, nothing to do here. Stopping now"); return 0; } /* end_of_emigrant */
JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_migrate(JNIEnv * env, jobject jprocess, jobject jhost) { msg_process_t process = jprocess_to_native_process(jprocess, env); if (!process) { jxbt_throw_notbound(env, "process", jprocess); return; } msg_host_t host = jhost_get_native(env, jhost); if (!host) { jxbt_throw_notbound(env, "host", jhost); return; } /* try to change the host of the process */ msg_error_t rv = MSG_process_migrate(process, host); if (rv != MSG_OK) { jmsg_throw_status(env,rv); return; } /* change the host java side */ (*env)->SetObjectField(env, jprocess, jprocess_field_Process_host, jhost); }
/* This function move the emigrant on Jacquelin */ static int policeman(int argc, char *argv[]) { xbt_mutex_acquire(mutex); XBT_INFO("Wait a bit before migrating the emigrant."); while (process_to_migrate == NULL) xbt_cond_wait(cond, mutex); MSG_process_migrate(process_to_migrate, MSG_get_host_by_name("Jacquelin")); XBT_INFO("I moved the emigrant"); MSG_process_resume(process_to_migrate); xbt_mutex_release(mutex); return 0; } /* end_of_policeman */
/** The guy we will move from host to host. It move alone and then is moved by policeman back */ static int emigrant(int argc, char *argv[]) { msg_task_t task = NULL; char *destination = NULL; MSG_process_sleep(2); while (1){ // I am an eternal emigrant MSG_task_receive(&(task), "master_mailbox"); destination = (char*)MSG_task_get_data (task); MSG_task_destroy (task); if (!destination) break; //there is no destination, die MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name(destination)); MSG_process_sleep(2); // I am tired, have to sleep for 2 seconds free (destination); task = NULL; } return 0; }