Skip to content

Parallel Libtrace HOWTO: Stopping

Shane Alcock edited this page Sep 21, 2015 · 2 revisions

In developing your libtrace program, a situation may arise where you want to force a parallel libtrace program to immediately exit all processing and reporting threads. For instance, the user may have signalled that they want the program to exit or the reporter may have seen sufficient results.

A parallel libtrace program can be halted by calling the trace_pstop function on the input trace. Calling this function will first cause each thread to be paused (triggering the pause callback if you have one), then send a message to each thread asking it to immediately stop. Each thread will then run their stop callback before exiting. Once all threads have exited, the trace_join() in your main loop will complete and your program will move into its cleanup phase.

An example signal handler that calls trace_pstop() is given below:

static void sigint_handler(int signum) {
    /* Assuming input is a global variable, otherwise we can't
     * access it from within our signal handler.
     */
    trace_pstop(input);
}

That concludes the Parallel Libtrace HOWTO. The only thing left to do is point out some potentially helpful examples included in the libtrace source code.

Clone this wiki locally