2

Is there a way to have a function raise an error if it takes longer than a certain amount of time to return? I want to do this without using signal (because I am not in the main thread) or by spawning more threads, which is cumbersome.

2
  • 1
    I'm pretty sure you actually want to use threads for things like this, because if a particular piece of code is hung (not just slow or blocked) its not going to be able to throw an error. Commented May 21, 2010 at 0:28
  • was you able to resolve this ?? i am facing the same issue Commented Feb 1, 2013 at 12:19

1 Answer 1

1

If your function is looping through a lot of things, you could check the elapsed time during each iteration of the loop... but if it's blocked on something for the long period, then you need to have some other thread which can be handling the timing stuff while the thread you're timing is blocked.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.