Can other models of concurrency be added to Go 2 or is that put of the question?

xuanbao · · 355 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Having Actor Model/Virtual Actor Model would be interesting to see. I know it goes against &#34;don&#39;t add what&#39;s not necessary&#34; but debate is still in the air over CSP vs Actor Model. Pipe dream wish, I know.</p> <hr/>**评论:**<br/><br/>earthboundkid: <pre><p>Am I the only one who feels like they are taking crazy pills when they read about async in C#/Python/JavaScript? It&#39;s so much less convenient than Go, but people act like it&#39;s great even though it&#39;s really just cooperative multitasking with a language keyword. It makes no sense to me. </p></pre>lhxtx: <pre><p>Yeah. I tried multiple times to grok asyncio on Py3 and just gave up. Either the documentation is that terrible or the library is that poorly engineered. </p></pre>Kraigius: <pre><p>I thought it was great with C# but then I stumbled across cases where it would deadlock because of the <em>context</em> of where you used it. So basically it&#39;s doing a lot of magic behind the scene and you actually need to be aware of what&#39;s going on and where to use the async syntax. You can&#39;t just read the code and understand it anymore.</p></pre>EZYCYKA: <pre><p>JS promises are quite interesting and make a lot of sense for front-end code where you are waiting for some data to come in from the back-end.</p></pre>TheMerovius: <pre><p>Honestly? I 100% prefer go&#39;s &#34;write synchronous code and let the runtime handle asynchronicity for you&#34; philosophy. I&#39;d much rather write (fake javascript using go&#39;s concurrency model):</p> <pre><code>function getData() { showSpinner(); try { data = get(&#34;/data&#34;); otherData = doSomethingElsePossiblyInvolvingTheNetwork(data); return doMoreStuff(data, otherData); } catch (e) { showErrorMessage(e); } finally { hideSpinner(); } } </code></pre> <p>than write (with promises):</p> <pre><code>function getData() { var data; showSpinner() return get(&#34;/data&#34;).then(function(d) { // Wait, how are you supposed to even do this idiomatically? This can&#39;t be it… data = d; return doSomethingElsePossiblyInvolvingTheNetwork(data); }).then(function(otherData) { doMoreStuff(data, otherData); hideSpinner(); }).catch(e) { showErrorMessage(e); hideSpinner(); // Am I understanding correctly, that promises have no finally? } } </code></pre> <p>(as you can tell, not great with javascript…). Go&#39;s concurrency model allows you, to write sequential code, without needing to <em>care</em> whether something you write will block or not. To make that work with javascript, it would need to a) spawn callbacks in a new user-land thread, b) would need to yield when doing (asynchronous) IO and schedule threads and… that&#39;s it, pretty much. You could also add some locking to browser-APIs that mutate state (like DOM-manipulations), but you could also just continue to let js run single-threaded. With that kind of concurrency support in the runtime, probably upwards of 90% of user-code could just be synchronous.</p> <p>The power of go&#39;s concurrenly model isn&#39;t so much channels and goroutines, it&#39;s the fact that all go code and all IO integrates nicely with it. I rarely actually use channels or goroutines and instead rely on things like <code>errgroup</code>. I still profit immensely from the go concurrency model, because the runtime will make sure that long-running IO will be interleaved efficiently - and in the end, that&#39;s the real goal.</p> <p>PS: Serious question though, how <em>are</em> you supposed to pass on some data in the continuation-style? I mean, I have <code>data</code> and a promise, returned by <code>doSomethingElsePossibly…</code> -- how do I pass both on?</p></pre>EZYCYKA: <pre><p>You can do <code>finally</code> by slapping a <code>.then</code> at the end (after <code>.catch</code>).</p> <p>It seems many share your sentiment though, as the new async/await looks very much like your first example.</p></pre>TheMerovius: <pre><p>async/await, AFAIK, still requires you to actually know about concurrency and whether a function blocks or not (and make that part of the API). I don&#39;t want to care.</p></pre>SSoreil: <pre><p>Other models of concurrency are normally designed to be implemented via a library. The model Go uses is already quite an exception to the rule in that it relies on language features.</p> <p>Why would a different model need to rely on language changes?</p></pre>corvuscrypto: <pre><p>This being said I <em>would</em> like it if you could specify priorities that the scheduler could recognize. A la boost&#39;s fiber scheduler</p></pre>shovelpost: <pre><p><a href="https://media.giphy.com/media/1M9fmo1WAFVK0/giphy.gif">But why?</a></p></pre>srbufi: <pre><p><a href="https://www.quora.com/How-are-Akka-actors-different-from-Go-channels" rel="nofollow">https://www.quora.com/How-are-Akka-actors-different-from-Go-channels</a></p></pre>shovelpost: <pre><p>When you originally posted this question, it had zero explanation.</p> <p>Anyways, the language is done. They wouldn&#39;t add other models of concurrency at this point. BUT they are discussing Go 2 at the moment. </p> <p>If you are really serious about this then you should create a concrete proposal and describe if you want a language change or if it could be added as a library, what problems it solves etc.</p></pre>srbufi: <pre><p>Re-read my post title. TL;DR &#34;could we add new concurrency models to Go 2&#34;</p></pre>shovelpost: <pre><p>TL;DR</p> <p>If you are really serious about this then you should create a concrete proposal that describes why, what problems it solves, how it is going to be implemented (language change, library, tooling), the impact on existing codebases etc.</p></pre>TheMerovius: <pre><p>Hm, but you can already have unbounded, asynchronous queues in go:</p> <pre><code>func asyncQ(ch &lt;-chan int) &lt;-chan int { out := make(chan int) go func() { var ( q []int send chan int next int } for send != nil &amp;&amp; ch != nil { select { case v, ok := &lt;-ch if !ok { ch = nil continue } q = append(q, v) next, send = q[0], out case send &lt;- next: q = q[1:] if len(q) == 0 { send = nil } else { next = q[0] } } } close(out) }() return out } </code></pre> <p>So, this seems to be perfectly expressible with the current concurrency primitives (though I&#39;d consider it a bad idea). It might be a bit unwieldy, but can be abstracted once in a library.</p> <p>There doesn&#39;t seem to be a particular need for adding this as a language feature.</p></pre>srbufi: <pre><p>Other models of concurrency: <a href="https://youtu.be/7AByMX76c_4?t=7m11s" rel="nofollow">https://youtu.be/7AByMX76c_4?t=7m11s</a></p></pre>youtubefactsbot: <pre><blockquote> <p><a href="http://youtu.be/7AByMX76c_4" rel="nofollow"><strong>Groovy and Concurrency with GPars [60:50]</strong></a></p> <blockquote> <p>This session looks at using Groovy for writing multithreaded, concurrent, and parallel programs. It briefly discusses leveraging legacy Java techniques such as multiple processes, multiple threads, the java.util.concurrent APIs, and shared-state atomicity. Then it considers some useful AST transforms in core Groovy (Lazy, Synchronized, Immutable, WithReadLock, and WithWriteLock) before diving headlong into GPars, a comprehensive library for parallel execution that provides a menu of options to the developer.</p> </blockquote> <p><a href="https://www.youtube.com/channel/UCdDhYMT2USoLdh4SZIsu_1g" rel="nofollow"><em><sup>JavaOne</sup></em></a> <sup>in</sup> <sup>People</sup> <sup>&amp;</sup> <sup>Blogs</sup></p> <p><em><sup>539</sup> <sup>views</sup> <sup>since</sup> <sup>Jun</sup> <sup>2015</sup></em></p> </blockquote> <p><a href="/r/youtubefactsbot/wiki/index" rel="nofollow"><sup>bot</sup> <sup>info</sup></a></p></pre>_youtubot_: <pre><p>Video linked by <a href="/u/srbufi" rel="nofollow">/u/srbufi</a>:</p> <table><thead> <tr> <th align="center">Title</th> <th align="center">Channel</th> <th align="center">Published</th> <th align="center">Duration</th> <th align="center">Likes</th> <th align="center">Total Views</th> </tr> </thead><tbody> <tr> <td align="center"><a href="https://youtu.be/7AByMX76c_4?t=7m11s" rel="nofollow">Groovy and Concurrency with GPars</a></td> <td align="center">JavaOne</td> <td align="center">2015-06-08</td> <td align="center">1:00:50</td> <td align="center">4+ (100%)</td> <td align="center">539</td> </tr> </tbody></table> <blockquote> <p>This session looks at using Groovy for writing...</p> </blockquote> <hr/> <p><a href="https://np.reddit.com/r/youtubot/wiki/index" rel="nofollow"><sup>Info</sup></a> <sup>|</sup> <a href="https://np.reddit.com/message/compose/?to=_youtubot_&amp;subject=delete%20comment&amp;message=dkx0rak%0A%0AReason%3A%20%2A%2Aplease+help+us+improve%2A%2A" rel="nofollow"><sup>/u/srbufi</sup> <sup>can</sup> <sup>delete</sup></a> <sup>|</sup> <sup>v1.1.3b</sup></p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

355 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传