Blog

20230121日志

2023年1月21日
2023
202301, goroutine停止, for循环下goroutine闭包, select多个channel, noticication channel, nil channel, buffered or not buffered channel, waitGroup, append是否会导致Data race

golang # 传播不合适的context # func handler(w http.ResponseWriter, r *http.Request) { response, err := doSomeTask(r.Context(), r) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } go func() { err := publish(r.Context(), response) // Do something with err }() writeResponse(response) } type detach struct { ctx context.Context } func (d detach) Deadline() (time.Time, bool) { return time.Time{}, false } func (d detach) Done() <-chan struct{} { return nil } func (d detach) Err() error { return nil } func (d detach) Value(key any) any { return d. ...

20230120日志

2023年1月20日
2023
202301, 线程, goroutine, data race, race condition, 内存模型, context

golang #

基本概念 #

不能直接创建Thread, 但是可以创建goroutine; os线程由os调度, goroutine在os线程内由goruntime调度; GOMAXPROCS定义产生多少OS线程, 在有block时, 还会生成新的OS线程, GOMAXPROCS默认等于机器的逻辑核心数; goroutine的状态, Executing: 在OS线程上运行, Runnable: 等待进入Executing, Waitting: stopped并等待一些事情完成(system call, sync, wait mutex); 1.14之前只会在chan send/recieve, i/o, wait mutext时发生context switch, 之后的版本会将运行超过10ms的goroutine标记为preemptible, 并有机会context-switched off被其他goroutine替换

goroutine_arrange

...

20230118日志

2023年1月18日
2023
202301, 单词

English # velocity n. 速度 insect n. 昆虫 swarm n. 一大群 v. 成群飞行 a swarm of insects bounce n. 反弹 v. 弹射 radius n. 半径 v. 成弧形 view radius 视觉半径 cohesion n. 内聚 alignment n. 对其 separation n. 分离 quadratic n. 二次方程式 adj. 二次的 minus adj. 小于0的 n. 负号 plus or minus 增减; 正负 acceleration n. 加速度 jittery adj. 紧张的, 敏感的 market jittery advertise v 为…做广告 to advertise cheap food flip v. ...

20230115日志

2023年1月15日
2023
202301, hugo

hugo # Hugo 基于golang template, 快速建站 github pages 无法接入百度,谷歌搜索 vercel 托管静态站点 域名 A记录:指向ip地址,CNAME: 指向其他域名, 参考阿里云域名服务页面

20230114日志

2023年1月14日
2023
202301, 非谓语动词

英语 #

非谓语动词(没有时间变化) #

  1. 做主语,宾语,表语,宾语补足语,定语,状语
  2. 加to为完全不定式,动词原形是裸不定式
  3. The rabbit liked to eat carrot
  4. To be or not to be, that is the problem
...

20230111日志

2023年1月11日
2023
202301, 英语综述, golang, for, grafana

英语 #

  1. 综述
    1. 5大句型
      • 主语+宾语: The rabbit slept (不及物动词)
      • 主语+宾语+谓语: The rabbit eat a carrot (单及物动词)
      • 主语+直接宾语+间接宾语: The rabbit teach you english (双及物动词)
      • 主语+谓语+宾语+宾语补语: The rabbit think you smart (复杂及物动词)
      • 主语+表语+谓语: The rabbit is smart (系动词)
    2. 10大词性
    3. 非谓语动词: 可以做谓语动词之外的其他成分
      • 现在分词
      • 过去分词
      • 不定式
      • 动名词
...