Stop functions in 5 minutes if they dont end running

Posted by george mano on Stack Overflow See other posts from Stack Overflow or by george mano
Published on 2012-06-24T02:42:01Z Indexed on 2012/06/24 3:16 UTC
Read the original article Hit count: 141

Filed under:
|

I want to add a feature in my project.

I have 2 functions running in a for-loop because I want to find the solution of the functions in random arrays. I also have an function that makes random arrays. In each loop the array that is made by the random_array fun are the input of the 2 functions. The 2 functions print solutions in the screen , they dont return an argument.

int main(){
    for (i=0;i<50 i++)
    {
    arr1=ramdom_array();
    func1(arr1)
    func2(arr1)
    }
}

I need to stop the functions running if they have not ended in 5 minutes. I have thought that I have to put in the functions something like this :

void func1(array<array<int,4>,4> initial)
{
while (5minutes_not_passed)
{
//do staff
if(solution==true)
break;
}
}

But I dont know what to put in the 5minutes_not_passed.

the declaration of the functions are like this:

void func1(array<array<int,4>,4> initial)
void func2(array<array<int,4>,4> initial)

I have found that I can use the thread library but I dont think meshing up with threads in a good idea. I believe something like a timer is needed. Note that the functions sometimes might end before 5 minutes.

© Stack Overflow or respective owner

Related posts about c++

Related posts about timeout