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.
Asked
Active
Viewed 762 times
2
-
1I'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. – yarmiganosca May 21 '10 at 00:28
-
was you able to resolve this ?? i am facing the same issue – gsagrawal Feb 01 '13 at 12:19
1 Answers
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.

Amber
- 507,862
- 82
- 626
- 550