Skip to content
Snippets Groups Projects
Commit 364be3b3 authored by Konstantin Osipov's avatar Konstantin Osipov
Browse files

A fix and a test case for gh-125: fiber cancel by numeric id.

Update the user guide.
parent 67b45d23
No related branches found
No related tags found
No related merge requests found
......@@ -2623,6 +2623,26 @@ procedures.
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis role="lua" xml:id="box.fiber.kill">box.fiber.kill(<replaceable>id</replaceable>) </emphasis>
</term>
<listitem>
<para>
Locate a fiber by its numeric id and cancel it. In
other words, combines <emphasis
role="lua">box.fiber.find()</emphasis> and <emphasis
role="lua">box.fiber.cancel()</emphasis> into one
</para>
<para>
Parameters: <code>id</code> = the id of the fiber to be cancelled.
</para>
<para>
Possible errors: the specified fiber does not exist or does not permit cancel.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis role="lua" xml:id="box.fiber.testcancel">box.fiber.testcancel()</emphasis>
......
......@@ -917,6 +917,26 @@ lbox_fiber_cancel(struct lua_State *L)
return 0;
}
/**
* Running and suspended fibers can be cancelled.
* Zombie fibers can't.
*/
static int
lbox_fiber_kill(struct lua_State *L)
{
if (lua_gettop(L) != 1)
luaL_error(L, "fiber.kill(): bad arguments");
int fid = lua_tointeger(L, -1);
struct fiber *f = fiber_find(fid);
if (f == NULL)
luaL_error(L, "fiber.kill(): fiber not found");
if (! (f->flags & FIBER_USER_MODE))
luaL_error(L, "fiber.kill(): subject fiber does "
"not permit cancel");
fiber_cancel(f);
return 0;
}
/**
* Check if this current fiber has been cancelled and
* throw an exception if this is the case.
......@@ -947,6 +967,7 @@ static const struct luaL_reg fiberlib[] = {
{"id", lbox_fiber_id},
{"find", lbox_fiber_find},
{"cancel", lbox_fiber_cancel},
{"kill", lbox_fiber_kill},
{"testcancel", lbox_fiber_testcancel},
{"create", lbox_fiber_create},
{"resume", lbox_fiber_resume},
......
No preview for this file type
......@@ -107,3 +107,9 @@ exec admin "lua f:resume()"
exec admin "lua fib_id = box.fiber.wrap(testfun):id()"
exec admin "lua box.fiber.find(fib_id):cancel()"
exec admin "lua box.fiber.find(fib_id)"
# gh-125 box.fiber.cancel() by numeric id
exec admin "lua function y() print('started') while true do box.replace(0, 'test', os.time()) box.fiber.sleep(0.001) end end"
exec admin "lua f = box.fiber.wrap(y)"
exec admin "lua box.fiber.kill(f:id())"
exec admin "lua while box.fiber.status(f) ~= 'dead' do box.fiber.sleep(0.01) end"
exec admin "lua box.space[0]:truncate()"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment