Lua Lanes:使用C库

我们正在运行一个通过Lua测试脚本测试的C库。这样运行得很好,但是我们决定是时候进行一些多线程操作了。因此,我们开始实施Lua Lanes,但卡在了为线程加载C库的过程中。

所以我们有一个名为test的函数,这是实际的测试套件函数(运行所有其他函数),作为一个开始,我尝试将其推入一个独立的线程,通过像这样调用它:

local pwlog = require "pwlog"
--一百万行代码,其中一个是测试函数
testF = lanes.gen("*", {required = {"pwlog"}}, tests)()

明确一下:local pwlog并不在函数中定义,而是全局定义的。

我根据这个进行了实现:https://github.com/LuaLanes/lanes/issues/108,但我发现很难弄清楚他的意思。好吧,这是错误的:

lua: /usr/local/share/lua/5.1/lanes.lua:327: main: function 'pwlogs/block_size' not found in Lane #0x2390770 destination transfer database

好吧,那么我尝试了另一种不同的方法。在我的测试函数顶部添加了一行额外的代码:

local function tests ()
    pwlog = require "pwlog"
    print("test")
--etc

并且我更改了调用方式:

testF = lanes.gen("*", tests)()

我认为这应该可以工作。这里直到线程创建后,pwlog才存在,因此我认为一切都会没问题。但它返回了一个非常困惑人的错误:

lua: /usr/local/share/lua/5.1/lanes.lua:327: can't copy non-deep full userdata across lanes

此错误是在以下行中抛出的:

testF = lanes.gen("*", tests)()

所以现在我卡住了。我应该如何将C函数加载到我的lua lanes线程中?

我正在使用Lua 5.1。

点赞