Re:The Way of the Gopher: Making the Switch from Node.js to ...
by vishbar on Sunday March 27, 2016 @07:27AM
(#11369641)
Go isn't just a threaded concurrency model, it uses an M:N greenthreads pattern. Also, when you say that Go I/O operations are blocking, it is true that they'll logically block a goroutine. However, under the hood, it uses the same libuv-style async IO (or IOCP on Windows) that Node does. An operating system thread doesn't get blocked; the goroutine is "shelved" and woken up again when the I/O is complete. It accomplishes the same kind of thing as Nodejs does, it just abstracts the async nature of the IO away from the programmer. I have to say I like it: procedural execution is easier to reason about.
[ Parent
| on HN ]
Re:The Way of the Gopher: Making the Switch from Node.js to ...
by Lukasa on Sunday March 27, 2016 @11:09AM
(#11370181)
Honestly, I think the distinction between M:N threading and straight OS threading is pretty minor. It grants some advantages to the language runtime: it can control the stack size, for example. But in terms of how it affects the development style and what kinds of bugs it encourages/discourages I don't think it dramatically differs from the OS threading model.
Re:The Way of the Gopher: Making the Switch from Node.js to ...
by sagichmal on Sunday March 27, 2016 @11:33AM
(#11370279)
It is categorically different. OS threads are orders of magnitude more expensive, which makes them a nonstarter for most problems that are a good fit for lightweight conceptual concurrency.
Re:The Way of the Gopher: Making the Switch from Node.js to ...
by Lukasa on Sunday March 27, 2016 @11:44AM
(#11370330)
It is not categorically different.
As I said above, green threading has advantages over OS threading, but they behave exactly the same in terms of design patterns and potential bugs.
This is what I was getting at when I said "not that different": compared to the difference between event-loop concurrency and threaded concurrency, M:N green threading is basically just a subcategory of threading.
Re:The Way of the Gopher: Making the Switch from Node.js to ...
by sagichmal on Sunday March 27, 2016 @03:14PM
(#11371093)
No. Green threads enable entirely new classes of design patterns that are categorically infeasible with OS threads.
Re:The Way of the Gopher: Making the Switch from Node.js to ...
by Rapzid on Sunday March 27, 2016 @09:50AM
(#11369933)
I believe that depending on the system call the thread handling the call could block, but it's not the same thread developer Goroutines are running on. Yeah though, same as nodejs.