fix: Ensure workers init before softints

main
Sean McBride 4 years ago
parent 86d997e2e2
commit 6e998a8143

@ -24,7 +24,8 @@ uint32_t runtime_processor_speed_MHz = 0;
uint64_t runtime_relative_deadline_us_max = 0; /* a value higher than this will cause overflow on a uint64_t */ uint64_t runtime_relative_deadline_us_max = 0; /* a value higher than this will cause overflow on a uint64_t */
uint32_t runtime_total_online_processors = 0; uint32_t runtime_total_online_processors = 0;
uint32_t runtime_worker_threads_count = 0; uint32_t runtime_worker_threads_count = 0;
uint32_t runtime_first_worker_processor = 0; const uint32_t runtime_first_worker_processor = 1;
/* TODO: the worker never actually records state here */
int runtime_worker_threads_argument[WORKER_THREAD_CORE_COUNT] = { 0 }; /* The worker sets its argument to -1 on error */ int runtime_worker_threads_argument[WORKER_THREAD_CORE_COUNT] = { 0 }; /* The worker sets its argument to -1 on error */
pthread_t runtime_worker_threads[WORKER_THREAD_CORE_COUNT]; pthread_t runtime_worker_threads[WORKER_THREAD_CORE_COUNT];
@ -85,8 +86,6 @@ runtime_allocate_available_cores()
if (runtime_total_online_processors < 2) panic("Runtime requires at least two cores!"); if (runtime_total_online_processors < 2) panic("Runtime requires at least two cores!");
runtime_first_worker_processor = 1;
/* Number of Workers */ /* Number of Workers */
char *worker_count_raw = getenv("SLEDGE_NWORKERS"); char *worker_count_raw = getenv("SLEDGE_NWORKERS");
if (worker_count_raw != NULL) { if (worker_count_raw != NULL) {
@ -181,17 +180,6 @@ runtime_start_runtime_worker_threads()
assert(ret == 0); assert(ret == 0);
} }
debuglog("Sandboxing environment ready!\n"); debuglog("Sandboxing environment ready!\n");
for (int i = 0; i < runtime_worker_threads_count; i++) {
int ret = pthread_join(runtime_worker_threads[i], NULL);
if (ret) {
errno = ret;
perror("pthread_join");
exit(-1);
}
}
exit(-1);
} }
void void
@ -251,6 +239,17 @@ main(int argc, char **argv)
#endif #endif
if (module_new_from_json(argv[1])) panic("failed to parse modules file[%s]\n", argv[1]); if (module_new_from_json(argv[1])) panic("failed to parse modules file[%s]\n", argv[1]);
listener_thread_initialize();
runtime_start_runtime_worker_threads(); runtime_start_runtime_worker_threads();
listener_thread_initialize();
for (int i = 0; i < runtime_worker_threads_count; i++) {
int ret = pthread_join(runtime_worker_threads[i], NULL);
if (ret) {
errno = ret;
perror("pthread_join");
exit(-1);
}
}
exit(-1);
} }

@ -57,6 +57,9 @@ sigalrm_propagate_workers(siginfo_t *signal_info)
for (int i = 0; i < runtime_worker_threads_count; i++) { for (int i = 0; i < runtime_worker_threads_count; i++) {
if (pthread_self() == runtime_worker_threads[i]) continue; if (pthread_self() == runtime_worker_threads[i]) continue;
/* All threads should have been initialized */
assert(runtime_worker_threads[i] != 0);
pthread_kill(runtime_worker_threads[i], SIGALRM); pthread_kill(runtime_worker_threads[i], SIGALRM);
} }
} else { } else {

Loading…
Cancel
Save