lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


In our framework, I patched lua to break the "infinite loop" like this :

https://github.com/cloudwu/skynet/commit/2086e13a4696792d32001f671821571fd27c6ab2#diff-77f29fbafba057306aa952d97c25d965

If the framework found the lua vm doesn't return for a long time, it can send a signal into the vm from other thread , and raise an error.


Rena <hyperhacker@gmail.com>于2015年9月3日周四 上午7:32写道:
On Wed, Sep 2, 2015 at 4:47 PM, Elias Barrionovo <elias.tandel@gmail.com> wrote:
> On Wed, Sep 2, 2015 at 5:36 PM, Rodrigo Azevedo <rodrigoams@gmail.com> wrote:
>> Is Lua a "infinite loop" safe language in any conception? (I really don't
>> know the strategies involved to check/avoid these cases at implementation
>> level)
>
>
> Alan Turing famously proved that there is no general way [1] of
> finding out whether a piece of program terminates for an arbitrary
> input without actually running it and hoping for the best. It's known
> as the Halting Problem: https://en.wikipedia.org/wiki/Halting_problem
>
> However, there are certain heuristics. For instance, you could create
> a graph of branches and function calls and see if there are any
> cycles, but it is very error prone (add some basic metatable or ENV
> trickery and the checker won't work).
>
> Usually, what is done is to limit the total runtime of a piece of
> code, which in Lua can be done using hooks and the debug library.
> Others in this list may enlight you in this matter.
>
> --
> NI!
>
> () - www.asciiribbon.org
> /\ - ascii ribbon campaign against html e-mail and proprietary attachments
>

Or just run a loop looking for any number which satisfies some
condition, for which it's not known whether any such number exists. No
analysis can tell you whether that program will ever finish.

--
Sent from my Game Boy.