lua-users home
lua-l archive

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





On Thu, Jun 12, 2014 at 3:42 PM, Thiago L. <fakedme@gmail.com> wrote:

On 12/06/2014 17:39, Andrew Starks wrote:



On Thu, Jun 12, 2014 at 1:47 PM, Thiago L. <fakedme@gmail.com> wrote:
I was playing around with coroutines and I think I found a bug when interrupting a running coroutine.
(I'm on windows so I'm gonna be using ctrl+c for the interrupt key, so it might not work for everyone)

When doing coroutines:

Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> =coroutine.resume(coroutine.create(function() while true do end end))
[hit ctrl+C here]

When doing pcall:

Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> =pcall(function() while true do end end)
[hit ctrl+C here]
false   interrupted!
>

So is this a bug or am I missing something?


The second case is straightforward. pcall fails because Lua was interrupted.

I believe that this is a case of who is receiving the interrupt. L receives it, and closes L and collects all garbage, including the coroutine, which never *really* closed. The main thread is what is shut down.

I'm probably being imprecise, but that's how i understand it.

-Andrew

It actually waits until the coroutine dies to process the interrupt... and either way it's still a bug...

In both cases, the main Lua state is closed/ interrupted. The coroutine never receives the signal because in order for that to happen, the main Lua state would need to pass it off to that thread. Instead, it simply closes, which means that the thread is collected, but the return value is never read or processed.

I can say with a pretty good level of certainty that it's not a bug, unless you think that Lua should pass EINTR to its coroutine, but given that it's not an OS thread, that would be weird.


-Andrew