4 ms·
Sadly it is probably your only choice if you want a multithreaded extension language playing nice with a multithreaded main application. For all other extensio
by Johnny_Brahms 9y ago
Sadly it is probably your only choice if you want a multithreaded extension language playing nice with a multithreaded main application. For all other extension languages I know, this is a huge hack that never works well in practice.
- cmacleod4 9y agoTcl has also fully supported this use case since about 1998.
- Johnny_Brahms 9y agoNot really. TCL didn't allow you to use one interpreter over several threads four years ago, and iirc TCL still isn't thread safe in that regard. Guile does this with bravura.
- cmacleod4 9y agoWell Tcl expects you to use an interpreter for each thread and pass messages between them, which is fairly easy. In Tcl 8.6 you also have the option to use multiple coroutines within one interpreter. This avoids the Global Interpreter Lock problem that plagues Python. How does Guile handle that?
- Johnny_Brahms 9y agoGuile doesn't. You'd use one interpreter and isolate whatever you need to isolate in it's own module and if you need things in parallel, you can just use pthreads (guile has proper threading support and no GIL). If you don't cross the C barrier again from your scheme code you can even use something like guile-fibers for Concurrent ML-like parallelism.
- deleted 9y ago[deleted]
- SwellJoe 9y agoHow is Lua so popular in gaming if it can't do this? (I don't know much about Lua except it has a pretty solid niche in some industries, and gaming is one of them.)
- freeone3000 9y agoLua extensions use coroutines instead of preemptive multithreading which is usually good enough.
- lucozade 9y agoLua fully supports scripting in multiple threads i.e. multiple threads can each have a Lua context that runs scripts independent of the other threads. Within a context you can run multiple coroutines but these are all run on the same thread and are cooperative. It doesn't natively support sharing across multiple OS threads.
- SwellJoe 9y agoI was reading the docs for Guile in this regard (https://www.gnu.org/software/guile/manual/html_node/Multi_002dThreading.html https://www.gnu.org/software/guile/manual/html_node/Multi_00...), and even with language support, it seems like you still need to jump through some hoops to do the Right Thing in a multi-threaded program. Seems like in any case, if I were using any of them in a threaded program, I'd want to isolate them from threads as much as possible. One of these days, in my Copious Free Time(tm), I'll take the time to actually look at an implementation to see how people have handled this problem. I wonder if any reasonably complete game engines use Guile, for comparison...
- Johnny_Brahms 9y agoThe only hoops I can see there is the regular caveats that apply to all parallel programming (don't introduce deadlocks, be careful: other threads might mutate the data you are currently using). That applies only if you are executing guile code in parallel in the same interpreter and environment (or asynchronously accessing interpreter data) which is impossible in insert_other_embeddable_language_here. You don't have to use embedded guile like that. From my experience: if you want to embed a language and only need it in a single thread, it is just as easy to use lua. If you want several interpreters in isolated threads without any communication Lua is easily the simplest solution. But if you need communication between multiple embedded language threads or interpreters you are better of with guile or TCL depending on what threading model you prefer.