Skip to content
Snippets Groups Projects
Commit 837a1486 authored by Jan David Mol's avatar Jan David Mol
Browse files

Task #5555: Catch exceptions in OMPThread::kill to make its use a great deal simpler.

parent d3453f58
No related branches found
No related tags found
No related merge requests found
......@@ -70,27 +70,31 @@ namespace LOFAR
// kill() will wait.
void kill()
{
while (!stopped) {
// Interrupt blocking system calls (most notably, read()),
// possibly multiple in a row.
// Note that the thread will stick around until the end
// of pragma parallel, so the thread id is always valid
// once it has been set.
pthread_t oldid = id;
if (oldid > 0) {
// Do not use THROW_SYSCALL(), because pthread_*() does not set errno,
// but returns it.
int error = pthread_kill(oldid, SIGHUP);
if (error != 0)
throw SystemCallException("pthread_kill", error, THROW_ARGS);
try {
while (!stopped) {
// Interrupt blocking system calls (most notably, read()),
// possibly multiple in a row.
// Note that the thread will stick around until the end
// of pragma parallel, so the thread id is always valid
// once it has been set.
pthread_t oldid = id;
if (oldid > 0) {
// Do not use THROW_SYSCALL(), because pthread_*() does not set errno,
// but returns it.
int error = pthread_kill(oldid, SIGHUP);
if (error != 0)
throw SystemCallException("pthread_kill", error, THROW_ARGS);
}
// sleep for 100ms - do NOT let us get killed here,
// because we're maintaining integrity
const struct timespec ts = { 1, 200 * 1000 };
while (nanosleep( &ts, NULL ) == -1 && errno == EINTR)
;
}
// sleep for 100ms - do NOT let us get killed here,
// because we're maintaining integrity
const struct timespec ts = { 1, 200 * 1000 };
while (nanosleep( &ts, NULL ) == -1 && errno == EINTR)
;
} catch(Exception &ex) {
LOG_ERROR_STR("Caught exception: " << ex);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment