Propagate stop request to simulation job
- Add
stop executable
in the cameo config xml file for the McStas simulation programs in order to get a soft kill signal
<application name="nhisto" starting_time="inf" retries="0" stopping_time="20" multiple="no" restart="no" pass_info="yes" log_directory="default">
<start executable="lstcameohisto128"/>
<stop executable="kill" args="-2 $PID"/>
</application>
- Make the start of the simulation in the mcstas server not blocking, so that it can wait for further requests
Something like
int main(...) {
...
std::unique_ptr<std::thread> thread;
while (true) {
if (request.type == SIMULATE) {
// check if a sim is already running: forbid new sim
...
if (thread.get() != nullptr) {
thread->join();
}
// pass request by raw pointer (no need to use a smart pointer)
thread.reset(new std::thread([...] {
simulate(request);
}));
}
else if (request.type == STOP) {
// It is better to get a new instance rather than share the one in the thread.
Instance sim = server.connect(app_name);
sim->stop();
}
}