I'd like to be able to run two threads that run forever (one thread computing some complex calculations, and the other counting the time and producing a timeout). As soon as the timeout thread reaches the required time, I'd like to stop both threads. I have tried doing this a couple of ways: first by running the first thread as a task and exiting the thread and then by using sections (by attempting to run #pragma omp cancel sections). This is what I have so far:
#pragma omp parallel num_threads(8) shared(break_out)
{
while (!break_out){
#pragma omp sections
{
#pragma omp section
complex_calc();
#pragma omp section
{
//Timekeeping
while(true){
current_time = std::chrono::high_resolution_clock::now();
wall_clock = std::chrono::duration_cast<std::chrono::duration<double>> (current_time - start_time);
if (wall_clock.count() > 0.99 * TIME_LIMIT){
break_out = true;
#pragma omp cancel sections
break;
}
}
}
}
}
}
**Point X**
The code is able to break out of the second section when the timeout occurs, but the first section still runs. Is there any way to return to 'Point X' in the program?