Skip to content

Commit

Permalink
check & join supervisor thread when terminating student program
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Guggi committed Nov 8, 2023
1 parent 0138292 commit 60fd0fb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/command/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ pub fn terminate_student_program(exec: &mut SyncExecutionContext) -> CommandResu

for _ in 0..20 {
std::thread::sleep(Duration::from_millis(100)); // Sensible amount?
let con = exec.lock().unwrap();
let mut con = exec.lock().unwrap();
if con.thread_handle.as_ref().unwrap().is_finished() {
con.thread_handle
.take()
.unwrap()
.join()
.or(Err(CommandError::NonRecoverable("Supervisor thread panicked".into())))?;
return Ok(());
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/command/execute_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ pub fn execute_program(
// WATCHDOG THREAD
let mut wd_context = exec.clone();
let wd_handle = std::thread::spawn(move || {
let exit_code = match supervise_process(student_process, timeout, &mut wd_context) {
Ok(code) => code,
Err(()) => 255,
};
let exit_code = supervise_process(student_process, timeout, &mut wd_context).unwrap_or(255);

log::info!("Program {}:{} finished with {}", program_id, timestamp, exit_code);
let sid = ProgramStatus { program_id, timestamp, exit_code };
Expand Down
2 changes: 1 addition & 1 deletion src/command/execution_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl ExecutionContext {
}

pub fn is_student_program_running(&self) -> bool {
self.running_flag
self.thread_handle.is_some()
}

pub fn has_data_ready(&self) -> bool {
Expand Down

0 comments on commit 60fd0fb

Please sign in to comment.