Builtin Watchdog for a sub (or block)by PetaMem (Priest)
|on Apr 28, 2002 at 14:22 UTC||Need Help??|
for reasons that are far beyond the scope of this node (and far beyond my english abilities to explain), I feel that there is a functionality missing, that'd bring qualitative advantage for coding a certain class of problems: Cheating God(s of computer science). :-)
I will try to give a very rough overview of my thoughts and would be very happy if some of you would find this problem worthy for a meditation.
Gödel's Undecidability Theorem (see here for a short introduction) - for some a very very theoretical thing - can be applied to some very real programming problems one can encounter with Perl: the standard halting problem for Turing machinesI'm excited about your input.
Let's say, you have some code given. Untested by you (or others), unknown to you. Probably all you know is, that it runs. You - however - don't know how long it will take to run. It may very well be, that it will run into an endless loop. The aforementioned Theorem by Gödel and the mathematical proof of the standard halting problem by Turing brought R. PENROSE to the conclusion, that machines will always lack a "functionality" people have: a machine cannot decide if a problem has a solution or not therefore it may stick for infinite time on computing a solution for an unsolvable problem 'till hell freezes.
This is exactly where Perl comes in. Hard things are possible and impossible things are just hard. Let's say you'd have something like that:
Let's forget for a moment about this MagicWatchdog thingie. The Wild computation is just an regexp searching for a string. If it finds it, cheatemall returns X, if it doesn't find it, Y is returned.
Now: We give the MagicWatchdog - say - 5 seconds. If everything what comes after the InitMagicWatchdog needs more than 5 seconds until the sub is exited, well - then a magic Watchdog exits the cheatemall sub with a return value of "Y".
Shouldn't be too hard to implement? Thought so. But the magic Watchdog has to be some kind of supervision to the whole Perl program, because it has to exit cheatemall with return value Y even if the program is currently in some other subroutine (which was called doing the wild computetions).
And finally - my brave monks - my brain completedly lost track what should happen if cheatemall calls recursively itself. Then - hapily - I found it again: The subroutine calling cheatemall has to simply init its own MagicWatchdog. So yes, it should be possible to have these Magic Watchdogs spread across the whole source.
What do you say? Could one enhance Perl, so that it'd provide this functionality? I searched but only found these (seem not related):