<p>Learning Go for a class. Trying to understand concurrency right now.</p>
<p>Is this <a href="http://pastebin.com/vkRNmjMX" rel="nofollow">example program</a> concurrent? What would it look like if it were/were not?</p>
<p>Is it as simple as removing the "go func" in the 24th line to make it concurrent?</p>
<hr/>**评论:**<br/><br/>djherbis: <pre><p>From a quick look, the example looks concurrent. The "go" keyword runs the following function concurrently in a goroutine.</p>
<p><a href="https://golang.org/doc/effective_go.html#goroutines" rel="nofollow">https://golang.org/doc/effective_go.html#goroutines</a></p>
<p>This link might be helpful as well:
<a href="https://www.golang-book.com/books/intro/10" rel="nofollow">https://www.golang-book.com/books/intro/10</a></p></pre>aylobng: <pre><p>Hm, so how would I go about making this program non-concurrent? Deleting "go func()" and "()" isn't enough. </p></pre>djherbis: <pre><p>In Go, we often use channels to communicate between concurrently running goroutines. In this case there are two channels "calc" and "result". The checkval function sends input on the "calc" channel to the goroutine running the "convert" function, where it receives the value computes the result and sends it back to the checkval function via the "results" channel. </p>
<p>To make it not-concurrent, you should take the computation being done in convert [the section of code between the send and receive] and use this code [possibly in its own function] in checkval instead of sending a value on "calc" and receiving it on "results".</p>
<p>Hope that helps.</p>
<ul>
<li>hopefully I'm not doing your homework for you, please read the links I posted above to get a more complete explanation of what goroutines and channels are.</li>
</ul></pre>mc_hammerd: <pre><p>should be enough.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传