草庐IT

concurrency-runtime

全部标签

concurrency - Go webcrawler 在检查大约 2000 个 url 后挂起

我有一个程序可以检查网页上是否有关键字。但是在检查了1000-3000个url之后,它挂起了。没有输出,不退出,tcp连接数为零。我不知道为什么没有新的连接。你能给我一些调试建议吗?typerequestReturnstruct{urlstringstatusbool}vartimeout=time.Duration(800*time.Millisecond)funccheckUrls(urls[]string,kwsstring,threadLimitint)[]string{limitChan:=make(chanint,threadLimit)ok:=make(chanreque

concurrency - 一次选择和多个案例

当同时收到C1和C2时,如何修改下面的代码来执行某些操作https://gobyexample.com/selectimport"time"import"fmt"funcmain(){c1:=make(chanstring)c2:=make(chanstring)gofunc(){time.Sleep(time.Second*1)c1 最佳答案 那可能是一个pipelinetechnique,calledfan-in:Afunctioncanreadfrommultipleinputsandproceeduntilallareclo

concurrency - 一次选择和多个案例

当同时收到C1和C2时,如何修改下面的代码来执行某些操作https://gobyexample.com/selectimport"time"import"fmt"funcmain(){c1:=make(chanstring)c2:=make(chanstring)gofunc(){time.Sleep(time.Second*1)c1 最佳答案 那可能是一个pipelinetechnique,calledfan-in:Afunctioncanreadfrommultipleinputsandproceeduntilallareclo

concurrency - map() 和 reduce() 是否适合 Go 中的并发处理?

我有python背景,刚开始接触Go,我发现自己在寻找Go中map()和reduce()函数的等价物。我没有找到它们,所以又回到了for循环。例如,这是我用来代替map()的,其中mapFunction在别处定义:data:=make([]byte,1024)count,err:=input.Read(data)//errorhandlingremovedfromthissnippetfori:=0;i这是我用来代替reduce()的方法,其中有2个状态变量,当代码遍历slice中的每个项目时,我使用它们来跟踪CSV中字段的引用:data:=make([]byte,1024)count

concurrency - map() 和 reduce() 是否适合 Go 中的并发处理?

我有python背景,刚开始接触Go,我发现自己在寻找Go中map()和reduce()函数的等价物。我没有找到它们,所以又回到了for循环。例如,这是我用来代替map()的,其中mapFunction在别处定义:data:=make([]byte,1024)count,err:=input.Read(data)//errorhandlingremovedfromthissnippetfori:=0;i这是我用来代替reduce()的方法,其中有2个状态变量,当代码遍历slice中的每个项目时,我使用它们来跟踪CSV中字段的引用:data:=make([]byte,1024)count

concurrency - Go语言中临界区的交替执行

我有两个go例程:funcf1{...somecode//criticalsection1(CS1)...criticalsectioncode//endcriticlasection1...morecode}funcf2{...somecode//criticalsection2(CS2)...criticalsectioncode//endcriticlasection2...morecode}funcmain(){gof1()gof2()}确保这些例程中的关键部分始终交替执行的正确方法是什么?换句话说,CS1应该只在CS2之后执行,反之亦然:CS1、CS2、CS1、CS2、CS1

concurrency - Go语言中临界区的交替执行

我有两个go例程:funcf1{...somecode//criticalsection1(CS1)...criticalsectioncode//endcriticlasection1...morecode}funcf2{...somecode//criticalsection2(CS2)...criticalsectioncode//endcriticlasection2...morecode}funcmain(){gof1()gof2()}确保这些例程中的关键部分始终交替执行的正确方法是什么?换句话说,CS1应该只在CS2之后执行,反之亦然:CS1、CS2、CS1、CS2、CS1

concurrency - 来自 fanIn 示例的 golang 并发模式

我正在关注RobPike2012年演讲中的Go并发模式示例(幻灯片来自此处:http://talks.golang.org/2012/concurrency.slide#30)。从“恢复序列”示例中,我一直收到错误:prog.go:21:cannotuseMessageliteral(typeMessage)astypestringinsendprog.go:43:msg1.strundefined(typestringhasnofieldormethodstr)prog.go:44:msg2.strundefined(typestringhasnofieldormethodstr)p

concurrency - 来自 fanIn 示例的 golang 并发模式

我正在关注RobPike2012年演讲中的Go并发模式示例(幻灯片来自此处:http://talks.golang.org/2012/concurrency.slide#30)。从“恢复序列”示例中,我一直收到错误:prog.go:21:cannotuseMessageliteral(typeMessage)astypestringinsendprog.go:43:msg1.strundefined(typestringhasnofieldormethodstr)prog.go:44:msg2.strundefined(typestringhasnofieldormethodstr)p

arrays - 在Golang中,为什么这样的类型转换会导致Runtime Error : index out of range?

我在做“围棋之旅”的练习,我所在的页面是https://tour.golang.org/moretypes/15下面是我的代码:packagemainimport"golang.org/x/tour/pic"funcPic(dx,dyint)[][]uint8{varret[][]uint8;varrow[]uint8;fori:=uint8(0);i当我运行这些代码时,控制台抛出一个错误:panic:runtimeerror:indexoutofrangegoroutine1[running]:panic(0x18b820,0x1040a010)/usr/local/go/src/r