Go协程与通道机制
Don’t communicate by sharing memory; share memory by communicating.
Goroutine
goroutine 与 thread
在 Go 中,应用程序并发处理的部分被称作 goroutines,它可以进行更有效的并发运算。协程由 Go 运行时 (runtime) 创建,和操作系统线程之间并无一对一的关系(user-kernel thread 映射模型):协程是根据一个或多个线程的可用性,映射(多路复用)在他们之上的。
协程调度器在用户态上对 goroutines 进行管理,采用 M:N 调度模型(M 个 Goroutine 映射到 N 个线程),可以用GOMAXPROCS(逻辑处理器数量)来控制 N 的数量。相比之下,线程是由操作系统内核进行管理和调度的,被操作系统调度器分配到不同的处理器核心上运行。由于没有内核的介入,协程的创建与切换的开销降低很多。具体来说,Go 采用协作式调度(通过 Gosched() 或 channel阻塞主动让出 CPU ),而线程则是由 OS 进行抢占式调度(RR, FCFS, … ...
Operating System Concepts: Process Scheduling
Attenion: we use process scheduling when discussing general scheduling concepts.
Key Objects
Introduce CPU-scheduling (object, method, criteria)
List some common CPU-scheduling algorithms
Q: Why we address CPU-scheduling instead of scheduling itself?
A: Scheduling of this kind is a fundamental operating-system function. Almost all computer resources are scheduled before use.
Basic Scheduling Concepts
Preemptive and Nonpreemptive Scheduling
1. Preemptive Scheduling
Definition: In preem ...
2024-1学习思考点滴汇总
Preface
我很喜欢姜夔诗《暗香》中的一句词:“等恁时、重觅幽香,已入小窗横幅”。身处在许多个“当时”的我并未能很好地把握好当下,诚然这有时间的局限性的原因,没法以全局的视角统筹好每一步,但我是可以做到的是不懈坚持与难以被外界干扰所消磨的热爱呀。“年年陌上生秋草”,待到回首,感觉自己并没有做什么,实现什么。可是再一步步往前看,却这学期的收获是要比上学期多得多的,但遗憾的还是没能完成自己制定好的计划和目标。
以下汇总了我在每日学习中的一些疑问与思考,它们对我来说意义重大,是我这一学期一点一滴收集起来的困惑、灵感与喜悦。我将它们按照特定的话题分类,在我以后有同样疑问时能快速地找回以前的答案,同时也不断以此不断勉励自己——不断思考、保持热爱!
软硬件技术
How the web works
实用的例子: How the web works - Learn web development | MDN (mozilla.org)
网站是如何构建起来的?bilibili
Principle of portability characteristic in Electron
从 Ele ...
Standford CS144 Lab 3
前言
时隔一个月又重新回到了 CS144 的实验当中,之所以做得如此之慢,主要原因还是自己能力不够(菜是原罪)。有时以为自己从“感性认知”上升到了“理性认知”,但将其运用到实践中时才发现,原来我还是什么都不懂,依旧停留在发展阶段。技术债方面,花了一周多补了 Git 的理论操作;知识债方面,还在继续边做实验边通过自顶向下复习(甚至可以说是学习)。认知和实践是无法割裂开来的,学习也是如此。同时也要认识到认知、理论和实践都具有时间局部性,唯一不变的就是“变”,惟其如此,才需要认知,实践,再认知,再实践。
实验概述
实验一开始我并没有对这个结构图有比较清晰的认识,但做到后面慢慢地发现它实在是精炼地描绘了整个 TCP Socket。
由于 TCP 是全双工的 (bidiretional),所以在 TCP 连接的发起方(发送方)以及连接的响应方(接受方)都是有Sender和Reciever两个部件的,不过为了简化讨论,就暂且称前者为发送方而后者为接收方。在 Lab1 和 Lab2 中我们实现了Receiver部件,在 Lab3 中我们就将实现Sender部件。
Sender 部件
以下介绍 ...
Operating System Concepts: Multithreaded Programming
Key objectives
Introduce the notion of a thread
Explicit threading - APIs for thread libraries
Implicit threading - kernel level thread management
Examine issues related to mutithreaded programming
Thread Concept
A thread is a basic unit of CPU utilization, in other word, a fundamental unit of CPU execution. It comprises of:
a thread ID, TID
a program counter
a register set
a stack
And it shares with other threads belonging to the same process:
code section
data section
operating-system res ...
Operating System Concepts: Process Concept
Key objectives
To learn the notion wof a process - a program in execution.
To describe the various features of processes, including scheduling, creation, and termination.
To introduce interprocess communication using shared memory and message passing.
Process Concept
1. The process
Informally, a process can be considered as a program in execution. While a program is a passive entity (often called an executable file), a process is an active entity with a PC spcifying the next instruction to ...
Git二周目学习
前言
上半年搭建完博客后初步了解了一下 git 的常用指令,第一次了解 git 这个版本控制工具,之后又零零散散地通过不同慕课和视频(Missing semester,南大 ICS和技术蛋老师)重温,可是我发现在学习过程中并没有很深入地去了解 git 的相关概念和具体操作之间的关系,实际使用中还涉及与远端仓库的交互,因此在做实验时总是搞得一团乱麻 (screw up)。学艺不精最终在实践中带来恶果,其中种种因缘和合且按下不表。最终我在痛定思痛后决心开启新周目的 git 学习,希望能真正地了解git,以后遇到问题不至于连 CSDN 的解决方法都看不懂。
学习内容
这次的学习的参考资料主要是 Pro Git,并且注重学习其中的具体概念。本篇博文会补充在一周目博文中没有记录的 command,同时通过具体实操例子来阐述 git 的概念与操作。
… , because if you understand what Git is and the fundamentals of how it works, then using Git effectively will probably be ...
Standford CS144 Lab 2
实验总览
官方文档对实验的描述如下:
In Lab 2, you will implement the TCPReceiver, the part of a TCP implementation that handles the incoming byte stream. The TCPReceiver translates between incoming TCP segments (the payloads of datagrams carried over the Internet) and the incoming byte stream.
The TCPReceiver receives segments from the Internet (via the segment received()method) and turns them into calls to your StreamReassembler, which eventually writes to the incoming ByteStream. Applications read from this ...
Standford CS144 Lab 1
Lab 1 项目构建
由于我对git不是很熟练,所以拉取和合并的操作有点麻烦。首先git clone -b lab1-startercode <url>拉取的是别人仓库 lab1 的 start code 到本地,然后git remote rm origin删除与远端仓库的联系,git remote add origin <[email protected]:usrname/reposname.git>和自己的远端仓库联系(<url>的话GitHub已经不支持用户密码登录了,最好是用SSH),再push到远端的一个新的分支上(我的分支名称叫lab1,用来保存starter code)。接着就和文档给出的步骤一样,git fetch同步一下,然后git merge origin/lab1,不出所料会发生merge conflict。
不用慌,进到文件夹里一点点 merge 就好。冲突解决完后git add ->git commit->git push行云流水推到 lab0 的分支上,最后make编译完成了项目初始化。
实验要求
总览 L ...
手机电话和微信语音——从两种即时通信技术的区别看通信网络的发展
问题产生
在一次帮家里老人办理运营商套餐时,我建议长辈要打电话的话就尽量用微信来打电话,而少用拨号的方式拨打移动电话。对此我和长辈的解释是:前者用的是“流量”,后者用的是“话费”,只要在有 WiFi 的环境下打微信电话就能不花话费了。但对于两者通话技术的区别,我却发现自己也是完全不了解,更别说和其他人解释“手机电话”和“微信电话”为什么一个用的是话费而另一个用的是流量了。
恰好最近在读《自顶向下》的无线网络和移动网络一章,便打算查阅书本和搜集网上资料,满足一下自己的好奇心,也借此机会锻炼一下写文章的能力。希望通过问题的引入,我们能够粗浅地从技术层面了解 2G-3G-4G 的通信网络发展。
讨论背景和问题概述
无论是用手机移动拨号还是通过微信语音视频进行通讯,手机作为(移动)主机(host)位于因特网边缘,是所谓的** “边缘设备” ** 。而这个边缘设备与我们平常的主机不同之处在于它是无线的(wireless),也就是说它和网络通信的下一跳(hop)之间是通过电磁波进行数据交换的。在接下来的探讨中,我们将注意力主要放在无线链路上,也即 OSI 参考模型中的链路层(Link laye ...