From: <don...@is...> - 2009-09-04 06:40:55
|
Vladimir Tzankov writes: > > It occurs to me that it would be useful to have a version of > > with-timeout that limits run time rather than real time. > > Is this easy to do? > Hmm, I do not think so (but my be I am wrong). I do not see way to > trigger an interrupt based on the run time (except some kind of > polling but it will not be efficient in general. better such polling > be implemented in the app code). Question 1: Is there a way to retrieve run time used by a thread? If so, I think it would be nice to make that visible to users. I had in mind a limit on the run time by the current thread, not the total run time of all threads. BTW, I notice that get-internal-run-time can increase twice as fast as get-internal-real-time when you use two processors - Hurray! Question 2: Is there a way to do something when a thread resumes or suspends? If so, you could, when a thread resumes, compute the remaining runtime allowed before a run-time limit and set an interrupt for that much real time into the future. Of course, you'd cancel such an interrupt on suspend, if you can get control at that point. Otherwise I guess you'd just ignore such interrupts that occur when you're suspended. If they cause you to resume, I guess I see no harm in that. |