Asynchronous tasks
|
03-11-2015, 06:12 AM
It isn't currently possible to create a new thread in Lua. Xoft did play around with it a while ago, but I wonder if:
03-11-2015, 06:16 AM
This is not possible with the current API. To implement the java API would involve significant development effort as we would need to implement a thread pool in C++. From the point of view of MCServer the simplest solution would be to implement a WebWorker style wrapper around cIsThread. However would this be too primitive an interface for plugin developers?
04-12-2015, 12:39 AM
Coming back to this, xoft do you think your LuaMultiThreaded could be implemented in MCServer? And if so, if I were to do an action that takes really long, for example a large for-loop, would it still block the server?
04-12-2015, 01:31 AM
It would need a lot of thought and probably a lot of testing. For example the threading might interfere with our callbacks, the objects currently guaranteed to be valid during the callback duration might get deallocated or another similar failure.
If if was implemented, a for loop would block the thread in which it was started. So if you started the for-loop in the world tick hook callback, bad idea. If you started it in the webadmin callback thread, no major problem there, the world goes on, only the webadmin will take ages to respond. It might even be possible to create a separate thread directly from Lua. Thanks given by: NiLSPACE
04-12-2015, 09:54 PM
It would be great if we could create new threads in Lua. That could allow WorldEdit for example to make big structures without blocking the server.
04-13-2015, 12:50 AM
Not likely, since writing the structure might still block the server for a considerable amount of time. True, much less than actually generating such a big structure.
You could already do a few things to avoid lag - for example make the command create a description of the operation, store it in a storage and have the world tick thread do a little bit of work on the queue of such operations at a time - for example generating, say, 10 slices of a big area.
function OnCmdGenerate(...) local operation = cGenerateStructure:new(...) table.insert(g_WorkQueue[worldName], operation) end function OnWorldTick(...) local workItem = g_WorkQueue[worldName][1] if (workItem ~= nil) then workItem:doABitOfWork() if (workItem:IsFinished()) then table.remove(g_WorkQueue, 1) end end end
04-13-2015, 01:29 AM
That would require allot of work though
![]() ![]()
04-15-2015, 09:49 AM
The API I suggested earlier get rid of a lot of these issues. You basically create a whole separate Lua State which gets a file passed to it process. It can only communicate with the parent via asynchronous message passing.
|
« Next Oldest | Next Newest »
|
Users browsing this thread: 1 Guest(s)