上一页 1 2 3 4 5 6 7 8 9 ··· 22 下一页
  2023年1月13日
摘要: 单机程序加锁的场景以及sync.Mutex介绍 简单的并发问题以及解决方案 在单机程序并发或并行修改全局变量时,需要对修改行为加锁以创造临界区。看一下下面的例子: type Counter struct { count int } func (c *Counter) incr() { c.count 阅读全文
posted @ 2023-01-13 14:21 江湖乄夜雨 阅读(336) 评论(0) 推荐(0) 编辑
  2022年12月29日
摘要: 配置及代码文件 { "name":"sasuke", "age":25, "gender":"male", "score":99.5 } develop.json package main import ( "crypto/md5" "encoding/hex" "encoding/json" "f 阅读全文
posted @ 2022-12-29 16:45 江湖乄夜雨 阅读(121) 评论(0) 推荐(0) 编辑
  2022年12月25日
摘要: 参考文章 Goroutine leak Golang中的goroutine泄漏问题 如何退出协程 goroutine (超时场景) 如何退出协程 goroutine (其他场景) 问题纠正 之前视频讲过一个知识点,如何设置子协裎超时机制,其实像下面这段代码,主协裎关闭后子协裎是不会停止的: func 阅读全文
posted @ 2022-12-25 10:51 江湖乄夜雨 阅读(519) 评论(0) 推荐(0) 编辑
  2022年12月18日
摘要: 参考博客: https://geektutu.com/post/hpg-sync-cond.html https://cyent.github.io/golang/goroutine/sync_cond/ 使用sync.Cond实现 如果想在使用 Cond 的时候避免犯错,只要时刻记住**调用 co 阅读全文
posted @ 2022-12-18 10:23 江湖乄夜雨 阅读(512) 评论(0) 推荐(0) 编辑
  2022年12月13日
摘要: 参考文章 [Golang]并发编程包之errgroup —— 文中最后那个ctx的坑注意一下! errgroup使用方法及适用场景 代码演示 package aerrgrouptests import ( "context" "fmt" "sort" "sync" "testing" "github 阅读全文
posted @ 2022-12-13 20:34 江湖乄夜雨 阅读(123) 评论(0) 推荐(0) 编辑
  2022年12月10日
摘要: 基本的单例模式 之前总结过博客:https://www.cnblogs.com/paulwhw/p/15450657.html#_label2 看一下Once的源码 type Once struct { done uint32 m Mutex } func (o *Once) Do(f func() 阅读全文
posted @ 2022-12-10 13:12 江湖乄夜雨 阅读(112) 评论(0) 推荐(0) 编辑
  2022年12月6日
摘要: 不带超时的写法 package concurrent_test import ( "fmt" "math/rand" "sync" "testing" "time" ) func init() { rand.Seed(time.Now().UnixNano()) } // 使用channel控制并发 阅读全文
posted @ 2022-12-06 16:46 江湖乄夜雨 阅读(150) 评论(0) 推荐(0) 编辑
  2022年12月2日
摘要: package gorm_tests import ( "fmt" "github.com/fatih/structs" "github.com/go-playground/validator/v10" "github.com/stretchr/testify/require" "gorm.io/d 阅读全文
posted @ 2022-12-02 19:55 江湖乄夜雨 阅读(981) 评论(0) 推荐(0) 编辑
摘要: package scripts_stroage import ( "fmt" "github.com/go-playground/validator/v10" "testing" ) // 参考博客: // https://juejin.cn/post/6900375680358285325 // 阅读全文
posted @ 2022-12-02 15:57 江湖乄夜雨 阅读(201) 评论(0) 推荐(0) 编辑
  2022年11月5日
摘要: expr_basic_test package expr_practice import ( "errors" "fmt" "github.com/antonmedv/expr" "testing" "time" ) // https://github.com/antonmedv/expr // 优 阅读全文
posted @ 2022-11-05 19:38 江湖乄夜雨 阅读(663) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 22 下一页