3 ms·
> Threads have a similar problem: if you use them, you're stuck using thread-safe libraries. One pattern that I like personally is the actor pattern. Building
by rdtsc 13y ago
> Threads have a similar problem: if you use them, you're stuck using thread-safe libraries.
One pattern that I like personally is the actor pattern. Building systems out of independent isolated concurrent components that share data _mostly_ by sending messages. Erlang at the top of this paradigm but one can replicate that in other languages and libraries. There is Akka for Scala and others as well. It is basically an object, a thread running one of its methods and a queue. This object also has an address or handle. Objects communicate by sending messages to each other's handles.
Now of course as you say one needs to use libraries that allow this concurrency.
So far I find this pattern best matches real world scenarios. Real world is built of many concurrent pieces but each individual piece could be a small sequential island. This doesn't apply just to intelligent agents but to server requests as well. Each client connection and context can be sequential but it can run concurrently with other potential client context.
Ideally if one such client request crashes it shouldn't crash the main OS process. If one such client goes into a tight loop it shouldn't block the rest of the requests. This is hard to do without sacrificing heavily by copying data and or using isolated heaps (can use real OS processes up to some point, but also it is very resource heavy).
> That's why you're talking about twisted-compatible libraries and not just python libraries, and why this a non-issue with node.js database libraries.
Very good point. I didn't think of it that way. Say if Python was born with Twisted bolted on to start we wouldn't be having this problem. But it is interesting how a mono-culture of concurrency is a good thing in certain respects. And to give Guido props I think he is trying to bring that in -- as with Python, it is desirable to have one best way to do the same thing. Concurrency wasn't like that historically. And he is trying to fix it. I personally disagree with the approach he took (either in promoting or looking at deferred or explicit co-routines based on generators)