MCPcopy Create free account

hub / github.com/SKeyerror/Psyduck / functions

Functions17 in github.com/SKeyerror/Psyduck

↓ 2 callersFunctionGetConfig
传统的双重校验锁方式,不过这种写法在其它一些语言中,例如 C++ 中,会因为指令重排的原因导致 Crash 所以其实现在很少有人会这么用,支持静态变量的语言都会利用“静态变量只会初始化一次”的特性来实现 而 Go 中则提供了 sync.Once 来实现单例
go-concurrency/mutex/mutex_test.go:42
↓ 2 callersFunctionGetOtherConfig
()
go-concurrency/mutex/once_test.go:18
↓ 1 callersFunctionAlternatelyPrint3
第三种方式,其实就是把第一种方式抽象了出来
go-concurrency/channel/alternately_print_test.go:81
↓ 1 callersFunctionMayBeReordering
指令重排是指写在程序中的两条语句在 CPU 执行时可能会出现,执行顺序与编写顺序不一致的情况。 也就是说,可能会出现 Done 被赋值成为 true 之后,才会去执行 msg = new(Message) 这两条指令 那么在 TestMemoryReordering 执行时,很有可能出现跳出了无限循
go-concurrency/memory/memory_reordering_test.go:21
↓ 1 callersFunctionfoo
(number int, mutex sync.Locker)
go-concurrency/mutex/mutex_test.go:9
FunctionAlternatelyPrint
有四个 goroutine,编号为 1、2、3、4。 每秒钟会有一个 goroutine 打印出它自己的编号,要求你编写一个程序, 让输出的编号总是按照 1、2、3、4、1、2、3、4、……的顺序打印出来。
go-concurrency/channel/alternately_print_test.go:13
FunctionAlternatelyPrint2
另一种实现方式
go-concurrency/channel/alternately_print_test.go:59
FunctionTestAlternatelyPrint
(t *testing.T)
go-concurrency/channel/alternately_print_test.go:103
FunctionTestGoroutineLeak
这段代码的问题就在于,使用了一个 unbuffered channel, unbuffered channel 只有在 receiver 和 sender 都准备好的时候才不会发生阻塞。 当任务执行时间超过 2s 时,定时器到期后直接退出 select {} 多路复用, 我们就再也不可能接收到 ch
go-concurrency/channel/goroutine_leak_test.go:13
FunctionTestMemoryReordering
(t *testing.T)
go-concurrency/memory/memory_reordering_test.go:27
FunctionTestOnceSingleton
(t *testing.T)
go-concurrency/mutex/once_test.go:35
FunctionTestRWMutex
(t *testing.T)
go-concurrency/mutex/rwmutex_test.go:10
FunctionTestRaceCondition
一个经典的 Race Condition 的入门例子,count 的结果取决于程序运行时的环境,也就是 多次运行,得到的 count 都会不一样 使用 go test -race race_test.go 可发现出该测试文件中存在的竞态问题
go-concurrency/mutex/race_test.go:13
FunctionTestReentrantMutex
fatal error: all goroutines are asleep - deadlock! 发生了死锁,也就是说,Mutex 是不可重入的。 因为 Mutex 在设计的时候,就没有把具体的 Goroutine 写入至 Mutex 的状态中, 因此所有的 Goroutine 的地位都是一样的
go-concurrency/mutex/mutex_test.go:24
FunctionTestSingletonConfig
(t *testing.T)
go-concurrency/mutex/mutex_test.go:59
FunctionTestTimeOutFunction
这里有一个关于 GC 的问题,假如下面儿的 ch 中装的堆变量,那么当函数运行结束后,ch 会被 GC 回收掉吗? channel 源码: https://github.com/golang/go/blob/2ebe77a2fda1ee9ff6fd9a3e08933ad1ebaea039/src/r
go-concurrency/channel/goroutine_leak_test.go:36
FunctionTestUnlockOtherCorLock
Goroutine g1 通过 Lock() 方法获取了锁,在 g1 持有期间,另一个 Goroutine g2 调用 Unlock() 想要释放这个锁,那么这个调用是否会成功? g1 还能不能正常运行? g2 能够成功调用 Unlock,但是后续 g1 调用 Unlock 时将会 panic。这操
go-concurrency/mutex/race_test.go:43