4 ms·
Python 3 has async coroutines built-in, and there are a number of libraries for Python 2 (e.g. twisted, tornado). Python 2 & 3 also have threading and multiproc
by mjohn 10y ago
Python 3 has async coroutines built-in, and there are a number of libraries for Python 2 (e.g. twisted, tornado). Python 2 & 3 also have threading and multiprocessing for concurrency.
Java, Rust & Ruby have built-in support for concurrency, but I haven't used those languages that much.
- ngrilly 10y agoMaybe I read "first-class" a bit too literally :-) > Python 3 has async coroutines built-in Yes, the asyncio library was introduced in Python 3.4. > there are a number of libraries for Python 2 (e.g. twisted, tornado) Yes, but they are not part of the language per se. > Python 2 & 3 also have threading and multiprocessing for concurrency. Threading and multiprocessing are really not a good fit when the number of concurrent processes increases, because each thread allocates its own stack, which can be quite expensive in terms of memory. This is the reason why Go (and maybe Erlang too but I'm not sure about the implementation) map "green" threads to OS threads, and implement a resizable stack. Libraries like gevent offer something similar for Python, with some low-level trickery. > Java, Rust & Ruby have built-in support for concurrency In the language and/or the standard library? In Java, there is Quasar and Akka, for example, but they are not part of the language/standard library.
- steveklabnik 10y ago> In the language and/or the standard library? In Rust, we have extremely strong concurrency support in the language/standard library in the form of our type system, which disallows data races at compile time. We only provide 1:1 threading, but libraries can use this type system to extend it: there's N:M threading libraries, as well as more exotic concurrency stuff than we provide directly. Rust also generally takes a "no batteries included" approach, generally speaking. In Ruby, there's Thread and Fiber. MRI's GIL hurts it here, but other implementations don't have this problem.
- ngrilly 10y agoCan you provide links to the Rust N:M threading libraries you recommend? How is the stack managed in these libraries (does it start small and is resized at runtime)? Same question for Ruby :-)
- steveklabnik 10y agohttps://crates.io/crates/mioco https://crates.io/crates/mioco https://crates.io/crates/coroutine https://crates.io/crates/coroutine I don't know much about the details, as I haven't used them myself, I just know they exist. http://ruby-doc.org/core-2.2.0/Thread.html http://ruby-doc.org/core-2.2.0/Thread.html http://ruby-doc.org/core-2.2.0/Fiber.html http://ruby-doc.org/core-2.2.0/Fiber.html