Es ist ein Prozess, der 100 Prozesse startet:Wie können Eigenschaften in SimGrid gleichzeitig richtig eingestellt werden?
for (int i = 0; i < 100; ++i) {
MSG_process_create("w", executor, NULL, MSG_host_self());
}
Ein Testamentsvollstrecker Probenaufgabe und führen Sie es schafft. Es gibt also 100 Prozesse, die gleichzeitig die Aufgabe ausführen und gleichzeitig beenden. Für die Anzahl der Prozesse überwachen habe ich void plusOneActiveProcess()
und void minusOneActiveProcess()
:
Durch alle executor
Prozesse gleichzeitig alles zu starten ist OK:
[ 0.000000] (2:[email protected]) Active process amount is 1
[ 0.000000] (3:[email protected]) Active process amount is 2
[ 0.000000] (4:[email protected]) Active process amount is 3
....................................................
[ 0.000000] (101:[email protected]) Active process amount is 100
Jeder der Prozesse verringern sollte (wie ich erwartet hatte) Schritt für Schritt Menge an aktivem Prozesse, wenn executor
beendet wurde, um die Aufgabe auszuführen. Aber es ist nicht passiert:
[100.000000] (101:[email protected]) Active process amount is 99
[100.000000] (2:[email protected]) Active process amount is 99
[100.000000] (3:[email protected]) Active process amount is 99
....................................................
[100.000000] (100:[email protected]) Active process amount is 99
Wie es richtig geht?
Dies ist der Code von Funktionen plusOneActiveProcess()
, minusOneActiveProcess
, executor()
:
int executor(){
plusOneActiveProcess();
msg_error_t a = MSG_task_execute(MSG_task_create("", 1e9, 0, NULL));
minusOneActiveProcess();
MSG_process_kill(MSG_process_self());
return 0;
}
void plusOneActiveProcess(){
char kot[50];
long number;
number = xbt_str_parse_int(MSG_host_get_property_value(MSG_host_self(), "activeProcess"), "error");
number++;
sprintf(kot, "%ld", number);
MSG_host_set_property_value(MSG_host_self(), "activeProcess", xbt_strdup(kot), NULL);
XBT_INFO("Active process amount is %s", MSG_host_get_property_value(MSG_host_self(), "activeProcess"));
memset(kot, 0, 50);
}
void minusOneActiveProcess(){
char kot[50];
long number;
number = xbt_str_parse_int(MSG_host_get_property_value(MSG_host_self(), "activeProcess"), "error");
number--;
sprintf(kot, "%ld", number);
MSG_host_set_property_value(MSG_host_self(), "activeProcess", xbt_strdup(kot), NULL);
//XBT_INFO("Active process amount is %s", MSG_host_get_property_value(MSG_host_self(), "activeProcess"));
memset(kot, 0, 50);
}