fix(frontends/lua): make sure Lua 'sleep' function support interruption

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-11-27 13:25:06 -08:00
parent 3a93212d5e
commit 0934d7b2f4
2 changed files with 12 additions and 2 deletions
src/frontends/lua
tests/lua/threads

View file

@ -549,8 +549,7 @@ static int check_interrupted(lua_State *) { // NOLINT
}
static int sleep(lua_State * L) {
std::chrono::milliseconds dura(luaL_checkinteger(L, 1));
std::this_thread::sleep_for(dura);
sleep_for(luaL_checkinteger(L, 1));
return 0;
}

View file

@ -0,0 +1,11 @@
S = State()
T = thread(S, [[
sleep(10000)
]])
T:interrupt()
local ok, msg = pcall(function() T:wait() end)
assert(not ok)
assert(is_exception(msg))
assert(msg:what() == "interrupted")