04 2021 档案

摘要:相比于Mutex来说,RWMutex锁的粒度更细,使用RWMutex可以并发读,但是不能并发读写,或者写写。 1. sync.RWMutex的结构 type RWMutex struct { // 互斥锁 w Mutex // held if there are pending writers // 阅读全文
posted @ 2021-04-28 18:23 卷毛狒狒 阅读(79) 评论(0) 推荐(0) 编辑
摘要:Mutex是go标准库中的互斥锁,用于处理并发场景下共享资源的访问冲突问题。 1. Mutex定义: // A Mutex is a mutual exclusion lock. // The zero value for a Mutex is an unlocked mutex. // // A 阅读全文
posted @ 2021-04-28 16:01 卷毛狒狒 阅读(110) 评论(0) 推荐(0) 编辑
摘要:一般程序的内存分配,从高位到低位依次为 全局静态区:用于存储全局变量、静态变量等;这部分内存在程序编译时已经分配好,由操作系统管理,速度快,不易出错。 栈:函数中的基础类型的局部变量;由程序进行系统调用向操作系统申请,由操作系统管理,速度快。每个线程有自己的栈区。 堆:使用malloc或new申请的 阅读全文
posted @ 2021-04-22 18:39 卷毛狒狒 阅读(1095) 评论(0) 推荐(0) 编辑
摘要:map的数据结构在 runtime/map.go 中定义。 type hmap struct { // Note: the format of the hmap is also encoded in cmd/compile/internal/gc/reflect.go. // Make sure t 阅读全文
posted @ 2021-04-21 19:21 卷毛狒狒 编辑
摘要:相比于List,环的结构有些特殊,环的头部就是尾部,所以每个元素可以代表自身这个环。环其实是一个双向回环链表。type Ring struct { next, prev *Ring Value interface{} // for use by client; untouched by this l 阅读全文
posted @ 2021-04-19 17:15 卷毛狒狒 阅读(138) 评论(0) 推荐(0) 编辑
摘要:container/list实际上是一个双向链表。 // Element is an element of a linked list.type Element struct { // Next and previous pointers in the doubly-linked list of e 阅读全文
posted @ 2021-04-19 16:29 卷毛狒狒 阅读(98) 评论(0) 推荐(0) 编辑
摘要:container/heap container/heap包对通用堆进行了定义并实现了标准堆操作函数,以此为基础可以很容易对各类堆和优先队列进行实现。 堆通常是一个可以被看做一棵树的数组对象。在队列中,调度程序反复提取队列中第一个作业并运行,因为实际情况中某些时间较短的任务将等待很长时间才能结束,或 阅读全文
posted @ 2021-04-19 15:43 卷毛狒狒 阅读(139) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示