代码之家  ›  专栏  ›  技术社区  ›  Etan bbum

从另一个线程调用Lua函数

  •  0
  • Etan bbum  · 技术社区  · 16 年前

    在我的示例应用程序中,我基本上有两个线程。

    因此,我想让它异步:当 downloadFile() processFile() 完成它。

    4 回复  |  直到 16 年前
        1
  •  3
  •   gwell    16 年前

    用户可以返回新的用户数据对象 downloadFile() 或用于启动线程的类似命名函数。这个新的用户数据对象将包含线程句柄,并有一个与 __index

    local a = downloadFile("foo")
    
    -- do other things
    
    a:join() -- now let the download finish
    
    processFile()
    

    或者这个:

    local a = downloadFile("foo")
    
    local busywork = coroutine.create(doOtherStuff)
    
    while(not a:finished()) do
      coroutine.resume(busywork)
    end
    
    processFile()
    
        2
  •  3
  •   lhf    16 年前

    LuaLanes 例如。阿尔索 here .

        3
  •  1
  •   user185231 user185231    16 年前

    没有将多线程集成到Lua(这并不难,Lua已经准备好了),您唯一的解决方案是处理C++中的信令。

        4
  •  0
  •   Judge Maygarden    16 年前

    归还 "future" object downloadFile 功能。这可用于检查长时间运行的异步操作的结果。看见 java.util.concurrent.Future QFuture mailing list thread coroutines .