summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Guittot <vincent.guittot@linaro.org>2015-09-11 14:43:11 +0200
committerVincent Guittot <vincent.guittot@linaro.org>2015-09-14 09:21:40 +0200
commit93bd40964c81c6137c54d25406256f4822c0950b (patch)
treeb0569da2740f5860ccd4051d0940c734714b34c4
parentdc08dc380cb32c7a9341176709334a363df3dcd5 (diff)
rt-app: fix deadlock
If a sigterm is raised once we have installed our own handler but threads are not already created, we deadlock in the shutdown function. So, we don't wait anymore for thread until all threads has been created which is not a big issue because we don't really care of gathering all logs and traces before exiting rt-app in this case as the use case has not started yet. Reported-by: Daniel Lezcano <daniel.lezcano@linaro.org> Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
-rw-r--r--src/rt-app.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/rt-app.c b/src/rt-app.c
index f14f228..5379ced 100644
--- a/src/rt-app.c
+++ b/src/rt-app.c
@@ -29,9 +29,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <sys/resource.h>
static int errno;
-static volatile int continue_running;
+static volatile sig_atomic_t continue_running;
static pthread_t *threads;
static int nthreads;
+static volatile sig_atomic_t running_threads;
static int p_load;
rtapp_options_t opts;
@@ -353,6 +354,10 @@ static void
shutdown(int sig)
{
int i;
+
+ if(!continue_running)
+ return;
+
/* notify threads, join them, then exit */
continue_running = 0;
@@ -364,7 +369,7 @@ shutdown(int sig)
}
/* wait up all waiting threads */
- for (i = 0; i < nthreads; i++)
+ for (i = 0; i < running_threads; i++)
{
pthread_join(threads[i], NULL);
}
@@ -634,6 +639,7 @@ int main(int argc, char* argv[])
/* allocated threads */
nthreads = opts.nthreads;
threads = malloc(nthreads * sizeof(pthread_t));
+ running_threads = 0;
/* install a signal handler for proper shutdown */
signal(SIGQUIT, shutdown);
@@ -664,6 +670,7 @@ int main(int argc, char* argv[])
log_ftrace(ft_data.marker_fd, "main creates threads\n");
}
+ /* Init global running_variable */
continue_running = 1;
/* Needs to calibrate 'calib_cpu' core */
@@ -835,6 +842,7 @@ int main(int argc, char* argv[])
(void*) tdata))
goto exit_err;
}
+ running_threads = nthreads;
if (opts.duration > 0) {
sleep(opts.duration);