MCPcopy Create free account

hub / github.com/daheige/concurrency-in-go / functions

Functions155 in github.com/daheige/concurrency-in-go

↓ 248 callersMethodPrintln
(args ...interface{})
part20/safe_go.go:29
↓ 4 callersFunctionconsumer
(ch <-chan int)
part10/pro_cust_async.go:93
↓ 3 callersFunctionproduct
(ch chan<- int)
part10/pro_cust_async.go:83
↓ 3 callersFunctionworker
(wg *sync.WaitGroup, n int)
part19/t.go:25
↓ 2 callersFunctioncatchRecover
()
part22/panic_catch/panic_catch.go:46
↓ 2 callersFunctionconsumer
(c <-chan int, done chan struct{})
part5/pro_cust.go:16
↓ 2 callersFunctiondoWork
()
part22/panic_catch/panic_catch.go:52
↓ 2 callersFunctiongenerator
不停地产生int
part12/select.go:32
↓ 2 callersFunctionprintNum
多任务资源竞争
part6/runtime_task.go:10
↓ 2 callersFunctionproduce
(p chan<- int)
part5/pro_cust.go:9
↓ 1 callersFunctionAsyncCallByCtx
AsyncCallByCtx 通过ctx timeout方式实现fn调度,超时就取消fn执行
part22/time_demo/main.go:55
↓ 1 callersFunctionAsyncCallWithCtx
AsyncCallWithCtx do task with ctx
part22/timeout/timeout.go:38
↓ 1 callersFunctionCatchStack
捕获指定stack信息,一般在处理panic/recover中处理 返回完整的堆栈信息和函数调用信息
part9/stack.go:56
↓ 1 callersFunctionConsumer
消费者
part11/chan_demo.go:22
↓ 1 callersMethodCount
()
part14/cache.go:17
↓ 1 callersMethodDo
Do 安全的执行fn
part20/safe_go.go:54
↓ 1 callersMethodDoQuery
DoQuery 模拟查询
part8/select_one.go:27
↓ 1 callersMethodGet
(string)
part14/cache.go:14
↓ 1 callersMethodIncrement
Increment 利用mutex枷锁和解锁机制 通过使用内存访问同步原语,你可以隐藏从呼叫者锁定关键部分的实现细节,但不会给调用者带来复杂性。 这是一个线程安全类型的小例子:
part2/demo.go:17
↓ 1 callersFunctionNew
New returns 创建一个safeGo实例
part20/safe_go.go:33
↓ 1 callersFunctionNewCache
(cacheType string)
part14/cache.go:109
↓ 1 callersFunctionProductor
生产者
part11/chan_demo.go:15
↓ 1 callersMethodSet
(string, interface{}, time.Duration)
part14/cache.go:15
↓ 1 callersFunctionStack
获取完整的堆栈信息 Stack returns a formatted stack trace of the goroutine that calls it. It calls runtime.Stack with a large enough buffer to capture the entir
part9/stack.go:42
↓ 1 callersFunctionTask
(taskch, resch chan int, exitch chan bool)
part11/chan_work.go:5
↓ 1 callersFunctionaddele
当启动多个goroutine时,如果其中一个goroutine异常了,并且我们并没有对进行异常处理,那么整个程序都会终止 所以我们在编写程序时候最好每个goroutine所运行的函数都做异常处理,异常处理采用recover
part11/cal.go:28
↓ 1 callersFunctioncal
(a int , b int )
part11/cal.go:8
↓ 1 callersFunctioncal2
(a int , b int ,wg *sync.WaitGroup)
part11/sync_demo.go:50
↓ 1 callersFunctioncal3
(a int , b int ,done chan bool)
part11/sync_demo.go:57
↓ 1 callersFunctionconsume
(data chan string)
part17/app_graceful.go:63
↓ 1 callersFunctionconsumer
(msgCh <-chan string)
part10/prodemo/app.go:70
↓ 1 callersFunctionconsumer1
(ch <-chan int)
part10/demo.go:28
↓ 1 callersFunctioncust
只能读取
part6/chan_3.go:22
↓ 1 callersFunctiondoStuff
(done chan struct{})
part12/ctx.go:31
↓ 1 callersFunctiongetUser
getUser 返回一个指针类型
part18/app.go:13
↓ 1 callersFunctiongetUser2
getUser2 模拟参数泄露
part18/app.go:19
↓ 1 callersFunctiongetUser3
getUser3 避免参数泄露,让返回值分配在堆上 .\app.go:25:15: moved to heap: u
part18/app.go:26
↓ 1 callersFunctionhandler
** 把上面的for{}打开 % go run ctx.go 2020/06/21 17:31:11 task exec begin 2020/06/21 17:31:16 timeout 2020/06/21 17:31:16 task exec end 2020/06/21 17:31:21 1
part12/ctx.go:71
↓ 1 callersFunctionlimit
(next http.Handler)
part16/http_rate.go:18
↓ 1 callersFunctionmakeRndNum
()
part8/select.go:10
↓ 1 callersFunctionprintNum1
多任务资源竞争
part6/chan.go:12
↓ 1 callersFunctionprintNum2
(n int)
part6/chan.go:21
↓ 1 callersFunctionproAndConsume
(exit chan struct{})
part17/app_graceful2.go:51
↓ 1 callersFunctionproduct1
(ch chan<- int)
part10/demo.go:18
↓ 1 callersFunctionproductDone
(ch chan<- int, done chan<- struct{})
part10/pro_cust_async.go:101
↓ 1 callersFunctionproduction
单方向的通道,写入
part6/chan_3.go:12
↓ 1 callersFunctionproduction
(data chan string, exit chan struct{})
part17/app_graceful.go:49
↓ 1 callersFunctionproduction
(msgCh chan<- string, done <-chan struct{})
part10/prodemo/app.go:46
↓ 1 callersFunctionpump1
(ch chan int)
part8/select_pump.go:19
↓ 1 callersFunctionpump2
(ch chan int)
part8/select_pump.go:25
↓ 1 callersFunctionquery
(conns []Conn)
part8/select_one.go:37
↓ 1 callersFunctionrpc
模拟rpc调用
part12/ctx.go:96
↓ 1 callersFunctionsend
(c chan int)
part11/select_case.go:12
↓ 1 callersFunctionshuffle
产生[0-n]之间的[]int
part12/dotask.go:15
↓ 1 callersFunctionsuck
(ch1, ch2 chan int)
part8/select_pump.go:31
↓ 1 callersFunctiontest
(ch chan int)
part5/gofunc.go:18
↓ 1 callersFunctiontest
()
part9/stack.go:16
↓ 1 callersFunctiontest
()
part6/runtime_2.go:8
↓ 1 callersFunctiontest
(c chan bool, n int)
part13/more_cpu.go:15
↓ 1 callersFunctionw
()
part15/chan_demo.go:70
↓ 1 callersFunctionworker
(id int, jobs <-chan int, results chan<- int)
part21/work_pool.go:34
FunctionAsyncCall
AsyncCall fn func() 通过timer模式进行超时控制
part22/time_demo/main.go:34
FunctionAsyncCall
AsyncCall 第一种:使用time.NewTimer
part22/timeout/timeout.go:14
MethodCount
()
part14/cache.go:78
MethodDel
(string)
part14/cache.go:16
MethodDel
(key string)
part14/cache.go:67
MethodExpire
(key string, duration time.Duration)
part14/cache.go:19
MethodExpire
(key string, d time.Duration)
part14/cache.go:125
MethodGet
(key string)
part14/cache.go:32
FunctionHelloHandler
(w http.ResponseWriter, req *http.Request)
part16/ratelimit/app.go:10
MethodIncr
(key string, step int64)
part14/cache.go:18
MethodIncr
(key string, step int64)
part14/cache.go:84
FunctionIndex
Index index.
part23/http_server_panic.go:43
FunctionMockPanic
MockPanic test panic.
part23/http_server_panic.go:48
MethodSet
(key string, val interface{}, d time.Duration)
part14/cache.go:50
Functionhello
()
part3/chan_sem.go:30
Functionhello2
()
part3/chan_sem.go:49
Functionhello3
fatal error: all goroutines are asleep - deadlock,产生死锁
part3/chan_sem.go:65
Functionmain
()
part2/demo.go:23
Functionmain
()
part12/dotask.go:21
Functionmain
()
part12/ctx.go:46
Functionmain
()
part12/select.go:9
Functionmain
()
part14/cache.go:145
Functionmain
()
part3/select_case.go:5
Functionmain
()
part3/select_break.go:9
Functionmain
()
part3/chan_2.go:5
Functionmain
()
part3/chan.go:9
Functionmain
()
part3/chan_sem.go:5
Functionmain
常见的超时处理
part3/select_after.go:9
Functionmain
()
part3/select.go:8
Functionmain
非安全性并发操作 在这个例子中,你可以看到,我们不需要通过通信同步内存访问或共享数据。
part4/production_2.go:11
Functionmain
()
part4/rnd.go:10
Functionmain
并发安全:将通道的读写约束在指定范围内
part4/production.go:6
Functionmain
()
part20/safe_go.go:9
Functionmain
构建一个缓冲型的 channel,容量为 4。接着遍历任务列表,每个任务启动一个 goroutine 去完成。 真正执行任务,访问第三方的动作在 w() 中完成,在执行 w() 之前,先要从 limit 中拿“许可证”, 拿到许可证之后,才能执行 w(),并且在执行完任务,要将“许可证”归还。 这样
part15/chan_demo.go:23
Functionmain
()
part15/server_http.go:13
Functionmain
()
part5/done_struct.go:8
Functionmain
()
part5/gofunc.go:5
Functionmain
()
part5/pro_cust.go:25
Functionmain
()
part9/app_2.go:10
next →1–100 of 155, ranked by callers