Asynchronous tasks
#21
Separate Lua States have similar shortcoming in the API department - it's not completely investigated whether the ForEachXYZ callback functions will keep their current semantics; all the callbacks will need their locks revised etc.
Reply
Thanks given by:
#22
I don't think that ForEachXYZ can be rewritten due to the mutation issues. But that is a disscusion for another thread. So I don't think this should be blocked by that.
Reply
Thanks given by:
#23
I think the threading model could probably look best like this:
Main thread collects all needed information -> Creates new thread to process it -> Calls a function in the main thread to do something with the processed information.

In WorldEdit it could look like this:
User uses "//set stone,dirt" ->
The selected area is read into a cBlockArea ->
A new thread is created with a function that fills the cBlockArea with stone and dirt ->
The thread calls a function in the main thread with the cBlockArea as a parameter ->
The main thread writes the cBlockArea back in the world.

The only thing that could block the server with this is the reading and writing of the cBlockArea, but I doubt that could be fixed easily.


Long story short, perhaps threads created by a plugin shouldn't interact with worlds, entities, players etc. Just process information that was collected before in the main thread.

If we'd expect the plugin developers to program threads like this would there still be a problem with the ForEachXYZ calls?
Reply
Thanks given by:
#24
There's no simple way to limit the thread's interaction with the rest of the server. As long as there's cRoot:Get():GetWorld() and similar functions, the worker thread could always interact with the main server with disastrous results.
On the other hand, if we remove the entire API form the thread's Lua state, then the thread cannot do any work at all - it wouldn't know how to interact with a cBlockArea and so on.
Reply
Thanks given by:
#25
You could change the __index metamethod in _G and other objects of the worker thread. If the thing the worker thread is trying to get is unsafe for multi threading then raise an error.

We'd have to make a list of all unsafe things like the whole cWorld class, cRoot:Get():GetWorld() and stuff
Reply
Thanks given by:
#26
There is a way of handling this. We can run tolua multiple times to generate multiple sets of bindings. That would enable us to disable unsafe functions.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)