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.
-
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– yarmiganosca2010-05-21 00:28:37 +00:00Commented May 21, 2010 at 0:28
-
was you able to resolve this ?? i am facing the same issuegsagrawal– gsagrawal2013-02-01 12:19:00 +00:00Commented Feb 1, 2013 at 12:19
Add a comment
|
1 Answer
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.