{"format":"brushup-mindmap-v1","id":"02-process-thread","title":"进程与线程【王道】","structure":"logic-right","theme":"auto","root":{"id":"f37bf1e445e9275f76f8ca793f","topic":"第二章 进程与线程","expanded":true,"children":[{"id":"67b4388c-cc9d-41f4-8fb2-999258365fd7","topic":"概念引出（哈工大）","expanded":true,"children":[{"id":"dddbc402ec9ad78f9056d91718","topic":"首先操作系统要管理CPU","expanded":true,"children":[{"id":"cfe15a38-dba3-45f4-a64f-fd3eee607a6f","topic":"I/O指令与计算指令运行时间差距极大，只执行一个程序CPU利用率低，为了使CPU忙碌起来、利用率提高","expanded":true,"children":[{"id":"ef8c4ffc-4828-44bb-aeb2-4452d187f88b","topic":"多道程序、交替执行（管理CPU核心，多进程图像）","expanded":true,"children":[{"id":"89b60ac7-1d52-49a1-878b-a996b5ef5009","topic":"因为需要切换程序，需要记录执行的程序，引入概念进程（与静态程序区分）","expanded":true}]}]}]},{"id":"542e723e-0997-47fc-9a8b-c6a0ac919958","topic":"进程","expanded":true,"style":{"borderColor":"#FF9F00","branchColor":"#EA8ABA"},"children":[{"id":"33ab8b70-36c7-4496-b381-a95409059acf","topic":"概念","expanded":true,"children":[{"id":"6b632eac-00bd-47da-a3a2-2c2c5003cb5e","topic":"程序一次执行过程，一次程序及其数据在处理机上顺序执行时所发生的活动","expanded":true},{"id":"07348502-8a42-41d6-8efe-4a90df0e1276","topic":"资源分配和调度的独立单位（未引入线程）","expanded":true}]},{"id":"dcc73f11-8cbc-4043-92b2-246619c3bbf1","topic":"进程实体（进程映象）","expanded":true,"children":[{"id":"f7b8f09a-3c33-4bf8-9c6d-45c14d375f98","topic":"PCB","expanded":true,"children":[{"id":"9f5436b5-e89d-4c5a-9926-19bf13ce46ca","topic":"进程描述信息","expanded":true,"children":[{"id":"aa2d25f8-850b-479d-9877-9dfcb39326ae","topic":"进程标识符PID（标志进程）、用户标识符UID（标识归属用户，为共享和保护服务）","expanded":true}]},{"id":"dab4e065-5788-4e53-89d0-29f8c2bb3e9d","topic":"进程控制和管理信息","expanded":true,"children":[{"id":"5ae02418-e44c-4216-a5af-2ec21f1fbbe2","topic":"进程当前状态、进程优先级、代码运行入口地址、程序的外存地址、进入内存时间、处理机占用时间、信号量的使用","expanded":true}]},{"id":"edb8ee17-98d9-45b8-9de6-92fcbaac7108","topic":"资源分配清单","expanded":true,"children":[{"id":"f0846df2-0140-4e33-8d40-da2c2144d063","topic":"说明有关内存地址空间或虚拟地址空间状况，所打开的文件列表和所使用的输入/输出设备信息","expanded":true},{"id":"d34ce2ac-6a63-44c8-9f97-08c2a1ef0e68","topic":"代码段指针、数据段指针、堆栈段指针、文件描述符、键盘、鼠标","expanded":true}]},{"id":"4b9af6d5-59e3-48b9-8bb3-b81d83c2e7cb","topic":"处理机相关信息","expanded":true,"children":[{"id":"23428bd3-c98e-42bd-9fb2-4b2045ce24ef","topic":"处理机中各寄存器的值（代码段指针、数据段指针、堆栈段指针、文件描述符、键盘、鼠标）","expanded":true}]}]},{"id":"6bbd55c2-5219-49ef-a269-268a2bc9928a","topic":"程序段","expanded":true,"children":[{"id":"ecf8f949-52f1-4983-9d75-e80b32dcbfa9","topic":"概念","expanded":true,"children":[{"id":"1cbfd6f3-7b2e-4690-8399-36e872ccb364","topic":"能被进程调度程序调度到CPU执行的程序代码段（指令序列）","expanded":true}]},{"id":"52e5ea0c-db4d-42d2-87e2-ab7745d241e5","topic":"共享正文段","expanded":true,"children":[{"id":"b1870a53-a654-48fe-a9e6-7c5852fec127","topic":"常量 + 代码","expanded":true}]}]},{"id":"8d2164ff-a81e-49a9-8de9-d69c307a9ed5","topic":"数据段","expanded":true,"children":[{"id":"1b36f143-d904-4cf6-811a-029df8578aad","topic":"概念","expanded":true,"children":[{"id":"af5d373f-37ea-4cb9-93d3-08ab61ec73b7","topic":"进程对应的程序加工处理的原始数据或者程序执行时产生的中间和最终结果","expanded":true}]},{"id":"ef09649c-5278-4941-807a-d5486328a569","topic":"数据堆段","expanded":true,"children":[{"id":"09d5376d-1e62-4d05-9018-2329a24bb938","topic":"动态分配变量 new malloc()","expanded":true}]},{"id":"a4f7abf5-93de-4eb9-8aa4-55285aaef706","topic":"数据栈段","expanded":true,"children":[{"id":"40870264-491e-412b-a7d8-9c8e949897f1","topic":"未赋值变量/函数实参","expanded":true}]},{"id":"80a97630-9441-4aa8-a0a4-54b7147a6767","topic":"全局区（静态区）","expanded":true,"children":[{"id":"7486eaa5-27dc-4165-aaa3-3383f34f5dab","topic":"全局变量/静态变量","expanded":true}]}]}]},{"id":"d65af67a-681e-4721-a625-f753dc2a8e74","topic":"进程控制块（PCB）","expanded":true,"children":[{"id":"6d58cf53-00f5-429b-a20f-f45fbae7247c","topic":"描述进程的基本情况和运行状态，进而控制和管理进程","expanded":true,"children":[{"id":"e29ed38e-f945-4c70-8387-8330ce24b10b","topic":"进程存在的唯一标志","expanded":true}]}]}]},{"id":"7d012b1d-e4d0-4013-b4ae-bff746f85351","topic":"多进程图像（操作系统核心）","expanded":true,"children":[{"id":"a19b7731-7311-44f4-9772-e41bdc2e3769","topic":"概念","expanded":true,"children":[{"id":"fc7bead8-6045-49b1-9649-c50c9fc951c4","topic":"用户只关系多个进程运行的样子，操作系统负责将多个进程向前推进","expanded":true}]},{"id":"764b6732-d49e-4e88-aab3-051e293175ce","topic":"多进程图像从启动开始到关机结束","expanded":true,"children":[{"id":"05da1461-059f-4336-9437-2c6a198af8ea","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-b1759235e9f7f7.png","width":343.35,"height":89.42},"children":[{"id":"b8d6c9f0-7f69-4628-9617-d8e7567212e3","topic":"操作系统创建1号进程（shell/Windows桌面），用户执行任务也是创建进程（通过1号进程）","expanded":true},{"id":"68a925fe-9ca3-4da6-9ea1-28479aa1badd","topic":"用户使用计算机就是启动了一堆进程，操作系统管理计算机就是管理一堆进程","expanded":true}]}]}]},{"id":"7f6387e5-a5c4-4c32-bb83-c9d0e32c007e","topic":"多进程如何组织（PCB+状态+队列）","expanded":true,"style":{"borderColor":"#FF9F00"},"children":[{"id":"b6e46c62-10b4-47e5-a5cc-b34892b8075e","topic":"PCB（上文）","expanded":true},{"id":"9c192cd3-3832-4c8a-9fd5-397950e71765","topic":"进程状态图","expanded":true,"style":{"borderColor":"#E32C2D"},"children":[{"id":"e797e0a5-3ab7-462b-9d8c-d8edfac76496","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-7f09d060fad115.png","width":552.52,"height":263.54},"children":[{"id":"8a1c0e48-588a-4e04-a0b6-7747e13b52cf","topic":"运行态：进程在处理机上运行","expanded":true},{"id":"c4b2b6f7-c445-462c-aeba-3f0adb22b2bc","topic":"就绪态：进程已处于准备运行状态","expanded":true},{"id":"001d34ef-54f3-40a3-8de2-4447c5af64ec","topic":"阻塞态（等待态）：进程正在等待某个资源而暂停运行","expanded":true},{"id":"9263d4d6-e387-4510-aa48-d168f7f50033","topic":"创建态：进程正在被创建，未进入就绪态","expanded":true},{"id":"a7af0518-c00c-4b2f-9217-77c080def5c4","topic":"结束态：进程正从系统消失（正常结束/异常终止）","expanded":true}]}]},{"id":"7b768993-7b51-483b-94b5-1915aff3b124","topic":"队列","expanded":true,"children":[{"id":"2a75496a-5cdd-4bba-9acc-f801a274483f","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-1fd40a18df3c41.png","width":400.87,"height":160.09},"children":[{"id":"f3dfd7dd-1516-4448-b160-96109e4d3f53","topic":"进程以队列形式组织","expanded":true}]}]}]},{"id":"c5585776-e0f1-412e-aa56-d6a2e4c53b25","topic":"多进程如何交替（队列操作+调度+切换）","expanded":true,"children":[{"id":"62510b43-50c1-4b94-9521-d01aca0fc6bb","topic":"队列操作","expanded":true},{"id":"7ea91130-7013-4470-9e88-06d7ce1826d3","topic":"调度（本章下文介绍）","expanded":true,"children":[{"id":"df1bcb4c-c286-493f-b3ae-14c388b01d12","topic":"核心是折中，需要考虑具体任务需求，平衡周转时间和响应时间","expanded":true}]}]},{"id":"87f6732a-bb79-4e9b-ab0d-fc8c529b8ae8","topic":"多进程如何影响（地址映射，内存管理章节介绍）","expanded":true,"children":[{"id":"a3fc037f-10d6-4c49-8f22-e69b76abd6fc","topic":"共享内存","expanded":true},{"id":"756bb020-4d82-4d0e-bfda-e960d6b6ffb5","topic":"映射表（逻辑地址与物理地址）","expanded":true}]},{"id":"6b1ce2b6-19c3-411d-bd6b-970aa4e34549","topic":"多进程如何合作（核心在同步，合理的推进顺序）","expanded":true,"children":[{"id":"b814c094-2479-49c4-933d-801e4aa09170","topic":"本章下文介绍","expanded":true}]}]},{"id":"dc36c1b9-9d55-4423-8469-1e0e835e7027","topic":"进程与线程","expanded":true,"children":[{"id":"e63e8fe3-8743-4ddd-8da4-b594f706a5ee","topic":"进程","expanded":true,"style":{"branchColor":"#007C74","fontSize":18},"children":[{"id":"1b496d19-084e-4d4b-9e70-0f80498b565f","topic":"进程控制","expanded":true,"children":[{"id":"b778c564-7cfc-485e-b4b7-43d76f3cab19","topic":"进程的创建（创建原语）","expanded":true,"children":[{"id":"408a92a6-8bc3-446b-9602-29e05b735c54","topic":"引起创建的事件","expanded":true,"style":{"borderColor":"#EB4D3D"},"children":[{"id":"d561f924-d34a-4354-a549-8b7290a4906a","topic":"用户登录","expanded":true},{"id":"f9575a58-e78f-43cd-a0cb-b5285722f590","topic":"作业调度","expanded":true},{"id":"d6368937-1e29-4384-b83f-fcd016d47b71","topic":"提供服务","expanded":true},{"id":"9eb2260e-93d0-411e-b6a1-c199564fbfc7","topic":"应用请求","expanded":true}]},{"id":"da916b3b-29ff-4589-9515-084b7dec507a","topic":"原语执行过程","expanded":true,"children":[{"id":"e98785a3-e1a4-4baf-b9af-f206f968fa22","topic":"分配进程标识号，申请PCB（PCB有限）","expanded":true},{"id":"d2f8d73f-ffc9-4c21-ab65-3f0d7c887bd5","topic":"为进程分配资源，为程序和数据以及用户栈分配必要的内存空间","expanded":true},{"id":"f56c4743-fc1d-4cd7-9037-bac399741eb5","topic":"初始化PCB，包括初始化标志信息、初始化处理机状态信息、初始化处理机控制信息、设置进程优先级","expanded":true},{"id":"a8b79f23-5363-4dfa-b693-7964aa3556ea","topic":"若进程就绪队列可以接纳新进程，进程就进入就绪态","expanded":true}]}]},{"id":"bd0339ae-6389-40af-9d17-e2e600b6850b","topic":"进程的终止（撤销原语）","expanded":true,"children":[{"id":"fec28b8f-efdb-43aa-8d4e-a86aae0d3f88","topic":"引起终止的事件","expanded":true,"children":[{"id":"03061f1d-eb96-484e-8d2e-80cc2fba7639","topic":"正常结束","expanded":true},{"id":"aafaf9fe-5dee-496b-a4eb-a319a504cf15","topic":"异常结束","expanded":true},{"id":"2cf46451-465b-48a1-9dc0-6abfc58e4061","topic":"外界干预","expanded":true}]},{"id":"080f1521-7bcf-4453-990a-5f13ba1c6000","topic":"原语执行过程","expanded":true,"children":[{"id":"0b956af5-8207-42cb-aa6d-c3b37e6805af","topic":"根据被终止进程的标识符，检索PCB，读取进程状态","expanded":true},{"id":"85ca70cf-c1b1-486a-8bc4-3709be76a9c5","topic":"若进程处于运行态，终止运行，剥夺处理机","expanded":true},{"id":"f7b45a6a-1d63-418b-a18f-6f4ba5c365c9","topic":"终止进程之下的子进程，该进程所有资源还给父进程或操作系统","expanded":true},{"id":"43f9f62c-1732-408f-b23b-0baf086a5bd4","topic":"PCB从队列中删除","expanded":true}]}]},{"id":"941c7278-5592-4a99-b51e-ec72d0c373f3","topic":"进程的组赛和唤醒","expanded":true,"children":[{"id":"d3670a44-de54-443d-9dbe-5b6c8db46208","topic":"阻塞（自我阻塞）","expanded":true,"children":[{"id":"a8dfea76-6606-45ac-be4e-0a47dbafcd33","topic":"引起","expanded":true,"children":[{"id":"92a0c7c5-0df3-4a6e-ac0f-0a3dd39971a3","topic":"需要等待系统分配资源","expanded":true},{"id":"a52c0e83-433f-4752-8010-09737898f4eb","topic":"需要等待相互合作的进程完成工作","expanded":true}]},{"id":"bf28c715-2e44-48e3-bc6e-e06d3fc9b8a7","topic":"原语执行过程","expanded":true,"children":[{"id":"23b83a48-dc3b-4b2d-907d-cf1ae28093b5","topic":"找到要被阻塞进程标识号对应PCB","expanded":true},{"id":"9bac9624-f0da-4c2e-979e-2716aa4d5dde","topic":"若该进程处于运行态，保护现场，状态转为阻塞态停止运行","expanded":true},{"id":"76bc14c3-761d-4c00-9627-fc1fb221ef99","topic":"将PCB插入对应等待队列","expanded":true}]}]},{"id":"1e2e0be9-4a4c-494e-97db-8b3bac67a83a","topic":"唤醒（其他进程唤醒）","expanded":true,"children":[{"id":"81640aac-972d-4db2-9500-964a8afb45f5","topic":"引起","expanded":true,"children":[{"id":"1aa0197b-ca24-43a0-92ab-c6884ae5111b","topic":"等待事件发生","expanded":true}]},{"id":"da63c8e6-d20a-419b-a775-83c2555c9134","topic":"原语执行过程","expanded":true,"children":[{"id":"3e874f7c-bb5f-4497-a223-386bab6a2a7d","topic":"找到等待队列中进程相应的PCB","expanded":true},{"id":"2b5b190c-9a46-4a80-88b8-2b692f364d9a","topic":"将其从等待队列中移出，状态置为就绪态","expanded":true},{"id":"8e040e9e-2b72-4b87-bdc1-9b482ac3d2b7","topic":"将PCB插入就绪队列，等待调度程序调度","expanded":true}]}]}]},{"id":"3a904993-dae4-48bc-9573-38c54a03ffd2","topic":"进程切换（运行态<-->就绪态，内核态下完成）","expanded":true,"children":[{"id":"827353d9-b268-4633-b6e8-96d11172d138","topic":"引起","expanded":true,"children":[{"id":"428533b7-df74-4181-ae4a-b3c280ddec3e","topic":"时间片到","expanded":true},{"id":"392c1127-1d2d-4e22-8e3b-df1ea96fd141","topic":"更高优先级到达","expanded":true},{"id":"4a216ae3-5356-4fba-9777-0231797c25ae","topic":"进程主动阻塞","expanded":true},{"id":"45b5348e-6d97-49e6-8394-6962ccfb0955","topic":"当前进程终止","expanded":true}]},{"id":"fe00befa-e4bd-4c3d-b594-1a3f2b2a8bac","topic":"原语执行过程","expanded":true,"children":[{"id":"adbc7c7b-2450-4d64-88c3-55ed9eac373f","topic":"挂起一个进程，保存处理机上下文，包括程序计数器和其他寄存器","expanded":true},{"id":"8ab4c560-e9e4-4c3e-8c37-b0a7351a73e7","topic":"更新PCB信息","expanded":true},{"id":"54e1d947-c06f-43a5-8dce-658226e54d58","topic":"把进程的PCB移入相应队列（就绪/阻塞队列）","expanded":true},{"id":"29d3d5b1-e97d-40ab-bbb4-3a271cdf6b21","topic":"选择另一个进程执行，更新其PCB，更新内存管理的数据结构","expanded":true},{"id":"1bed31c2-07d8-4caf-9695-fdb9a872b83e","topic":"跳转到新进程PCB中的程序计数器所指位置","expanded":true},{"id":"431cb83e-e173-49f9-aa1d-202eb724df9c","topic":"恢复处理机上下文","expanded":true}]}]}]},{"id":"8a07d478-1e8f-4a16-8ea9-59e170783d17","topic":"进程通信","expanded":true,"style":{"borderColor":"#FF9F00"},"children":[{"id":"01980ed4-5fe7-4152-8eb2-50129eb8ad73","topic":"共享存储","expanded":true,"children":[{"id":"304fcca0-56cc-48e1-959e-2c865ab226de","topic":"概念（进程<--->共享空间<--->进程）","expanded":true,"children":[{"id":"ba95fcc1-7c62-45a1-b8ab-821e47d2fefd","topic":"通信进程间存在直接访问共享空间，实现信息交换","expanded":true}]},{"id":"2b1172cc-abcc-4e42-beea-32b1a14299b0","topic":"操作系统只负责为通信进程提供可共享使用的存储空间和同步互斥工具，数据交换由用户安排读写指令完成","expanded":true,"children":[{"id":"648a4300-7438-4cfb-a209-df3751d5bc57","topic":"低级方式：基于数据结构共享","expanded":true},{"id":"bf5cdbbb-0f04-4bd2-bd12-3578ef0173e0","topic":"高级方式：基于存储区共享","expanded":true}]}]},{"id":"c30c75bc-5e31-4e86-9892-3bca0a6a16f5","topic":"消息传递","expanded":true,"children":[{"id":"25a2cdfc-79df-45a9-b41c-2826729d49e1","topic":"概念","expanded":true,"children":[{"id":"4d88670f-72d7-42f9-83ff-a7a6b34146b2","topic":"以格式化的消息为单位进行数据交换，通过系统提供的发送消息和接收消息原语实现","expanded":true}]},{"id":"fcd08b90-096d-44e6-92f3-358e2fe894a5","topic":"直接通信方式","expanded":true,"children":[{"id":"2aaf55be-dcc1-4a44-8c35-97ab406d69bf","topic":"发送进程将消息挂在接受进程的消息缓冲队列上","expanded":true}]},{"id":"4060210b-4e86-4eb5-b749-ae294223e7a8","topic":"间接通信方式","expanded":true,"children":[{"id":"c44d7148-392b-4e75-9f15-1926f4e8afb1","topic":"发送进程把消息发送给某一个中间实体，接收进程从中间实体中获得消息（电子邮件系统）","expanded":true}]}]},{"id":"ec0a7ab1-3d9f-4fc5-8a9e-bb4c95abaede","topic":"管道通信（一种特殊共享文件，缓冲区，受文件系统管理）","expanded":true,"style":{"borderColor":"#EB4D3D"},"children":[{"id":"492ab9bc-b127-4817-9c5d-e45608f2ccff","topic":"发送进程以字符流形式将大量数据写入管道，接收进程取","expanded":true,"children":[{"id":"e84aa58e-bf15-4861-b878-bcdd09b4632b","topic":"当管道写满时，写进程阻塞，等待读进程将数据取走","expanded":true}]},{"id":"e1303c73-8c5e-4ba5-aaa4-d2851973aab1","topic":"管道半双工通信，不可同时读写（全双工通信则双管道）","expanded":true,"style":{"borderColor":"#EB4D3D"},"children":[{"id":"3f4194aa-e5bd-41b5-a7cc-43058b50623c","topic":"管道变空后，读进程阻塞","expanded":true}]},{"id":"f211e4c9-c0b7-4b5b-b4cc-17dbd73c6e9e","topic":"只能一个读进程，可以多个写进程","expanded":true,"style":{"borderColor":"#EB4D3D"}}]}]},{"id":"a61847d1-5d7f-464f-b30b-257d41fbd4f4","topic":"进程与作业","expanded":true,"children":[{"id":"c927967c-89fe-426a-839d-2d397180043a","topic":"作业是用户提交，以用户任务为单位，进程是系统自动生成，操作系统控制为单位","expanded":true,"children":[{"id":"aed431eb-2157-4f81-a6bc-6c889b27ce34","topic":"一个作业可能对应多个进程","expanded":true}]}]}]},{"id":"4443e9be-04a3-44a0-accd-070e9bf3ac74","topic":"线程","expanded":true,"style":{"fontSize":18},"children":[{"id":"b04305d6-6f82-4c7a-a24e-bcd51723398b","topic":"概念","expanded":true,"children":[{"id":"519935f2-08dc-4ed0-8d83-de37310d83e9","topic":"为减少程序在并发执行中的切换开销，引入线程概念（切线程不切进程则资源不用切换）","expanded":true},{"id":"784b36fd-00f1-4fe7-8063-4afc51326ddc","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-ad5d9e3eb522e5.png","width":529.93,"height":210.28},"children":[{"id":"ad10748f-b1c0-4406-996f-cdfc1d66b65c","topic":"进程 = 资源 + 执行执行序列（将资源和指令执行分开）","expanded":true},{"id":"709dc2ce-28d9-4811-b1eb-934c56b832d7","topic":"线程","expanded":true,"children":[{"id":"279433c5-4896-43e9-a361-743a4e80a249","topic":"进程内（在一个资源下）启动多个轻巧的、可以来回切换的指令序列","expanded":true},{"id":"3f20c1f9-c574-42f4-b669-0d5121c86167","topic":"保留了并发的优点，避免了进程切换的代价","expanded":true}]},{"id":"1fd74f91-29f8-471e-b451-666702afd342","topic":"此处李治军老师进程切换的内容，分离为线程的指令的切换与映射表上资源的切换两部分讲，讲解内存管理的时候再讲资源问题，两者分离讲解，进程切换问题迎刃而解","expanded":true}]},{"id":"1001b9a3-9025-400b-b08d-cbedb2c7c861","topic":"调度","expanded":true,"children":[{"id":"682d751b-8185-4d1a-8f5c-9dfab3286c47","topic":"引入线程前","expanded":true,"children":[{"id":"f8c3f55c-8a0f-419b-b265-e12a8d7df3dd","topic":"进程是资源和独立调度的基本单位","expanded":true}]},{"id":"018f2f68-b01d-4c94-9e4b-02b98b755cca","topic":"引入线程后","expanded":true,"children":[{"id":"260b94d1-08ba-44bd-9eb4-b49944f85018","topic":"线程是独立调度的基本单位，进程是资源的基本单元","expanded":true,"children":[{"id":"dcf6d986-77ac-4ffc-835f-2801b18f21a1","topic":"进程仅为系统资源分配单元，线程处理机分配单元（服务单元）","expanded":true}]}]}]},{"id":"d7df6652-75a9-48c0-acc5-32283d2fa11c","topic":"进程的地址空间相互独立，统一进程的各线程之间共享进程的资源，某进程的线程对其他进程不可见","expanded":true}]},{"id":"ae2ffde2-378d-42b6-a001-e610bc05fa96","topic":"线程控制块TCB","expanded":true,"children":[{"id":"86405afe-7007-424b-83a3-3cddfd2ad18e","topic":"线程标识符、线程运行状态、优先级","expanded":true},{"id":"c093e49c-305a-4465-83b9-5963191a7f3f","topic":"线程切换保存/恢复","expanded":true,"children":[{"id":"aa4b7f5a-af60-4727-904a-c12a5578e43f","topic":"程序计数器PC、其他寄存器、堆栈指针","expanded":true}]}]},{"id":"0295f8f4-893b-473c-b95b-1e0180a72b83","topic":"实现方式","expanded":true,"children":[{"id":"40a88b74-cef9-427c-a751-6b028185590c","topic":"用户级线程ULT","expanded":true,"children":[{"id":"c216b0fc-27d5-417b-a9f2-d9b0267c2512","topic":"有关线程管理的所有工作都由应用程序完成，内核意识不到线程的存在","expanded":true}]},{"id":"07201974-093f-495d-aa77-458e2409df92","topic":"内核级线程KLT","expanded":true,"children":[{"id":"71a3514a-d182-4efb-8952-64f74801aded","topic":"线程的管理工作全部由内核完成","expanded":true}]},{"id":"fe8d4a47-6ad4-4c7b-9f91-884a44b85f2d","topic":"用户级线程与内核级线程：一个栈到一套栈","expanded":true}]},{"id":"39b9901c-dc11-4af2-a7e0-a8c97c8fd662","topic":"多线程模型","expanded":true,"style":{"borderColor":"#E32C2D"},"children":[{"id":"e59c21ca-cf7d-41c4-9459-26a1736a6365","topic":"多对一模型","expanded":true,"children":[{"id":"fbdf2317-3f85-4aca-957c-baae731f0057","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-3409200cffcbe1.png","width":264.19,"height":222.2},"children":[{"id":"34b18e7c-1f66-4d10-885d-8c1f87da20fd","topic":"经多个用户级线程映射到一个内核级线程，线程管理在用户空间完成，用户级线程对操作系统不可见","expanded":true},{"id":"fcf31620-1a91-4d50-bddb-20ff1230a6df","topic":"线程管理在用户控件，无需切换","expanded":true},{"id":"9cb1da2b-1d36-4d43-8ce9-1010d9be2a83","topic":"一个线程阻塞，全部线程阻塞","expanded":true}]}]},{"id":"618b8c1a-2766-4ecf-81f6-b5deee3e3117","topic":"一对一模型","expanded":true,"children":[{"id":"417a2dea-5a46-46b6-b4b5-8ff149405fcb","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-b8e26606fe9ad2.png","width":263.79,"height":245.35},"children":[{"id":"0f6a3874-94b3-4c07-929b-9e7731794fda","topic":"每个用户级线程映射到一个内核级线程上","expanded":true},{"id":"227d812e-07b8-44ad-b514-c82bdb50b6b0","topic":"创建线程开销大，切换频繁影响应用程序性能","expanded":true}]}]},{"id":"2cecf359-59ef-4f0a-bb82-11bea20cb42d","topic":"多对多模型","expanded":true,"children":[{"id":"bc9f582d-4a09-4a37-a8b4-72edc886759b","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-836a3a9391b32d.png","width":260.68,"height":257.94},"children":[{"id":"7f32d914-d985-44ee-b3bd-a912ecb1e9e3","topic":"多个线程映射到多个内核线程上","expanded":true},{"id":"bf273019-e16c-4348-9d9b-6551e3430015","topic":"结合上述两种，既可提高并发性，有降低开销","expanded":true},{"id":"595d954a-3868-411d-9130-00d19ca5f12a","topic":"用户级线程：代码逻辑载体","expanded":true},{"id":"4db251a8-88f7-4463-ae52-58462665857e","topic":"内核级线程：运行机会载体","expanded":true}]}]}]}]}]},{"id":"aa35eeea-863b-498f-a6cf-af4fca808993","topic":"处理机调度","expanded":true,"children":[{"id":"31a72cc6-1a00-45ca-85d2-1b2c1ccf7f66","topic":"调度","expanded":true,"style":{"borderColor":"#FF9F00"},"children":[{"id":"bf776482-aaac-44a1-8e4b-cf2c1e26a5da","topic":"调度的层次","expanded":true,"style":{"borderColor":"#B796D9","branchColor":"#BA69C8"},"children":[{"id":"eb9a2ddc-d0ed-4941-b676-7a469963dd93","topic":"作业调度（高级调度）","expanded":true,"children":[{"id":"f3fe961d-db56-4d0c-86fe-f52159a86bdc","topic":"每个作业只能调入一次，调出一次","expanded":true,"children":[{"id":"2d92800a-5e67-429f-bdca-afa9e93b5cb5","topic":"辅存<--->内存","expanded":true}]}]},{"id":"c03f8e85-553d-4d2c-a755-567979aa1226","topic":"内存调度（中级调度）","expanded":true,"children":[{"id":"e18ed073-d03e-45f1-ab0e-f0c0c8877f35","topic":"将不能运行的进程调至外存，具备运行条件的进程调入内存，提高内存利用率和系统吞吐量","expanded":true,"children":[{"id":"e95012f5-11b2-4aad-a072-1e8ffdeec473","topic":"内存<--->外存，就绪态<--->挂起态","expanded":true}]}]},{"id":"1af03599-0bb6-40bc-bdbf-c8074a194864","topic":"进程调度（低级调度）","expanded":true,"children":[{"id":"bfa1d60a-da45-4afc-860d-2b6b6d978030","topic":"按某策略从就绪队列选取一个进程分配处理机","expanded":true,"children":[{"id":"aed7c190-45ec-4f02-a84b-6ec309ae5421","topic":"处理机<--->内存，最基本，高频","expanded":true}]}]}]},{"id":"3041549f-f869-4bdf-898f-060e68bee92d","topic":"调度的时机","expanded":true,"children":[{"id":"1943438a-f552-4720-b7fa-ab3bacff2f57","topic":"不能切换的情况","expanded":true,"children":[{"id":"5bb7837d-73e0-41e1-aa1c-1d049fc3b2f4","topic":"处理中断过程","expanded":true},{"id":"7a8f12b0-041e-4294-b8ae-ff16e07f757d","topic":"进程在操作系统内核程序临界区的时候","expanded":true},{"id":"fed88577-2ef5-4094-b7ed-c1c9aa94e433","topic":"其他需要完全屏蔽中断的原子操作过程","expanded":true}]},{"id":"6e81c86b-3a3e-45a3-b611-446027b15103","topic":"可以切换的情况","expanded":true,"children":[{"id":"20c1d1fe-9685-47f7-862b-2a6ae39ccaf0","topic":"发生引起调度条件且当前进程无法继续进行（非剥夺）","expanded":true},{"id":"67d4fea8-477d-4c31-aa28-43e835200ba6","topic":"中断处理结束或者自陷处理结束后（剥夺）","expanded":true},{"id":"c817363e-3a00-4cd9-94d1-7f7a364790bc","topic":"具体","expanded":true,"style":{"branchColor":"#BA69C8"},"children":[{"id":"0215011e-133d-4eed-96e7-52e0b418fe07","topic":"创建新进程","expanded":true}]}]}]},{"id":"7649bb30-c76e-4a07-a2bd-6afd231d278e","topic":"进程调度方式","expanded":true,"children":[{"id":"edb2a9e6-49d7-4310-b1bf-4f86b672bf17","topic":"非剥夺调度方式","expanded":true,"children":[{"id":"75e014a2-935b-4ceb-8328-de0ec93cb7e3","topic":"高优先级进程需要等待占用处理机的进程释放","expanded":true},{"id":"ecfb5291-a2dc-4719-addc-45f0e50ff57d","topic":"实现简单开销小，适合大多数批处理系统，不适用于分时系统和大多数实时系统","expanded":true}]},{"id":"c449c1a0-8d38-448d-b575-ec6bab36ead0","topic":"剥夺调度方式","expanded":true,"children":[{"id":"1e5a0bcb-fda7-4b10-a6f0-19b7271b1750","topic":"暂停执行的进程，处理机分配给更高级进程","expanded":true},{"id":"255cf755-e56a-4847-bd57-1dfe5b2453aa","topic":"提高系统吞吐量和响应效率","expanded":true}]}]},{"id":"3b1bedbe-02b8-40d3-8044-8a6d47d1426c","topic":"调度的参考","expanded":true,"style":{"branchColor":"#BA69C8"},"children":[{"id":"8617b8e9-8fbd-4668-8bba-6e9d9ae871c0","topic":"CPU利用率：尽可能保持CPU处于忙碌状态=忙碌时间/总时间","expanded":true},{"id":"def64dc7-da59-4204-b95b-182c1ea49d67","topic":"周转时间：从任务进入到任务结束 = 完成作业时间 - 到达时间","expanded":true},{"id":"060179d7-4a5e-452e-bc4b-aa6f74789aca","topic":"响应时间：从操作发生到响应","expanded":true},{"id":"736f4f09-0a4d-4085-9152-10652053aaa8","topic":"等待时间：作业等待处理机时间=周转时间-运行时间-I/O操作时间","expanded":true,"children":[{"id":"adc7d6f5-b9d6-46b5-93fd-7a1a770df8e9","topic":"作业需计算在外存后备队列中的等待时间","expanded":true}]},{"id":"16ce9ea9-2b42-487d-9a74-b4a7a70a7daa","topic":"吞吐量：完成的任务量=总完成任务数/总花费时间","expanded":true},{"id":"56b7bd62-63d9-4614-82e6-80057334af20","topic":"响应时间小->切换次数多->系统内耗大->吞吐量小","expanded":true},{"id":"922757da-9e18-47fc-9d82-66cdb30e9cf3","topic":"前台任务关注响应时间，后台任务关注周转时间","expanded":true},{"id":"a82e71da-be12-491e-bfce-2ef4f8983fd3","topic":"CPU约束型任务：CPU多、I/O少","expanded":true},{"id":"514258d5-ec05-4584-afc7-9a54b01a4979","topic":"I/O约束型任务：I/O多、CPU少","expanded":true,"children":[{"id":"2589426a-3fe7-4740-8a6f-4518286c39a6","topic":"优先级高","expanded":true}]}]}]},{"id":"cfcc5d86-1793-4ba4-9c8c-4343c5fdbf5a","topic":"进程的挂起态与七状态模型","expanded":true,"style":{"borderColor":"#FF9F00"},"children":[{"id":"11548e00-3416-4872-945c-2619288a0e66","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-619ee297f0314d.png","width":505.39,"height":205.24},"children":[{"id":"ab828c3c-cde8-4ccf-95bd-9e800a8f6057","topic":"挂起态：暂时调到外存等待的进程状态为挂起状态","expanded":true},{"id":"b4370e11-c370-403c-b681-fa63a6c16b95","topic":"挂起态和阻塞态都是暂时不能获得CPU服务，挂起态将进程映像调到外存，阻塞态仍在内存","expanded":true}]}]},{"id":"8cda8fa3-c60e-419b-b432-fbc858c8918d","topic":"经典调度算法","expanded":true,"style":{"borderColor":"#E32C2D"},"children":[{"id":"16b039ad-1c83-4e58-9204-737f48139694","topic":"先来先服务算法 FCFS","expanded":true,"children":[{"id":"c49efef9-917d-4f4e-a979-7dc08291a456","topic":"有利于CPU繁忙（长作业），不利于I/O繁忙型作业（短作业）","expanded":true,"style":{"borderColor":"#EB4D3D"},"children":[{"id":"9174be6d-0051-4084-8c78-35905544d299","topic":"不会饥饿","expanded":true}]}]},{"id":"98b40e73-f7ba-4981-b850-33de78d52fd1","topic":"短作业优先算法 SJF","expanded":true,"children":[{"id":"24c614e2-7bc8-4a50-8af2-e2551b60ebd5","topic":"非抢占式算法（若抢占式，则为最短剩余时间优先算法）","expanded":true,"children":[{"id":"bbe0c624-6cd5-4d5c-b4b8-00a9c1f9902f","topic":"可能饥饿","expanded":true}]}]},{"id":"3a7d9242-c95a-4a05-9d88-5dae44140fd8","topic":"优先级调度算法","expanded":true,"children":[{"id":"fab830dc-3007-4919-af00-ee0a2f143b89","topic":"原则","expanded":true,"children":[{"id":"5701282a-77ef-4f3b-a2f2-e3e9a535b5c4","topic":"系统进程>用户进程","expanded":true},{"id":"5f630c61-46d4-489f-ae9c-a4b6b224cd77","topic":"交互型进程>非交互型进程","expanded":true},{"id":"f4a0c1bf-384f-48ec-8128-d31e763b2fee","topic":"I/O进程>计算型进程（CPU繁忙型）","expanded":true},{"id":"196bea28-af53-43ea-93dc-523a52f92a06","topic":"前台进程>后台进程","expanded":true}]},{"id":"eb4fa046-7ea8-424d-984c-f2742a20d59c","topic":"可能饥饿","expanded":true}]},{"id":"fa94d777-de27-435a-b849-23b8a27bf0cc","topic":"高响应比调度算法 HRRN","expanded":true,"children":[{"id":"78cd26bf-31c7-4773-8be5-0de56ae36846","topic":"响应比 =（等待时间+要求服务时间）/ 要求服务时间","expanded":true,"style":{"borderColor":"#EB4D3D"},"children":[{"id":"89356add-f9c4-45dc-a459-c79d18b2460e","topic":"不会饥饿，非抢占式算法","expanded":true}]}]},{"id":"74ee912f-3504-47b7-9f65-4e89e000dd4e","topic":"时间片轮转算法 RR","expanded":true,"children":[{"id":"386c92bc-c0bf-4078-8dc4-1a82c66baee9","topic":"时间片用完进入就绪队列队尾","expanded":true,"children":[{"id":"de86dfa5-7d0c-423b-94cd-ca41295204d7","topic":"不满足短作业优先，不会饥饿，抢占式算法","expanded":true}]}]},{"id":"0cacb91c-c624-4afa-98ea-7dec24a55624","topic":"多级队列调度算法","expanded":true,"children":[{"id":"283619cc-ff5b-46e6-bde3-9c3485734a71","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-f1c86a525c2783.png","width":445.08,"height":204.44},"children":[{"id":"a1a43977-81be-4ade-afa6-e774aabdf5cf","topic":"设置多个就绪队列，将不同类型或性质的进程固定分配到不同就绪队列","expanded":true},{"id":"4f3b292a-1dfa-4ee0-835a-851d458130f5","topic":"队列间可采用","expanded":true,"children":[{"id":"b764b74d-9da0-49e1-ad34-325ea35f67e5","topic":"固定优先级：高优先级空时优先级低才能调用","expanded":true},{"id":"a40b1c24-e822-49a6-8553-a97b2d047b39","topic":"时间片划分：例如，列队分配时间50%、40%、10%","expanded":true}]},{"id":"05b4c5f0-cc90-4ae2-892a-2e80cc7e7a36","topic":"各队列可不同调度策略：系统队列采用优先级调度、交互式队列采用RR、批处理队列采用FCFS","expanded":true}]}]},{"id":"d4fb15bf-fc47-444f-9e82-aaeb10d7ea29","topic":"多级反馈队列调度算法","expanded":true,"children":[{"id":"dc9db145-a27e-4aca-87a7-08a4e75fbc2d","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-efe36468ce9824.png","width":405.93,"height":242.02},"children":[{"id":"38f64ebd-3959-49c5-a4cc-83e49295a1a8","topic":"设置多个就绪队列，每个队列赋予不同优先级","expanded":true,"children":[{"id":"40b7011d-3f2b-4f66-8eeb-8d6f8dd6586c","topic":"第一级队列优先级最高，依次递减","expanded":true}]},{"id":"60d9ead4-41c6-47ae-88e2-ebb1dc8bb8df","topic":"赋予每个队列的进程运行时间片大小各不相同","expanded":true,"children":[{"id":"5d3474d0-59ca-45f3-9be4-0b4b9b1df122","topic":"优先级高，进程时间片小","expanded":true}]},{"id":"5f2f9c95-2af0-422b-9177-76555022bec5","topic":"每个队列都采用FCFS算法","expanded":true,"children":[{"id":"0cb4cde2-9ad8-4c7a-a8c7-df0780f68c7c","topic":"第n级队列后，采用时间片轮转算法","expanded":true}]},{"id":"a05358cb-859d-48e3-935e-8361514c7310","topic":"按队列优先级调度","expanded":true,"children":[{"id":"f6374895-5d36-41b3-96d3-e93cb2b240e4","topic":"只有高级队列为空时，低等级队列才能调度","expanded":true,"children":[{"id":"68bc2118-fa25-460e-9d82-024b6a82e80c","topic":"若被抢占，则未运行完队列回到本队列队尾","expanded":true}]}]},{"id":"67247cf5-4679-471b-9aaf-b6ee9059186c","topic":"优势","expanded":true,"children":[{"id":"d49f413a-628b-44c9-b25a-1268bf15b7a6","topic":"终端型作业用户：短作业优先","expanded":true},{"id":"2aba031f-f720-4e00-a2bc-5dc43c9234b3","topic":"短批处理作业用户：周转时间较短","expanded":true},{"id":"a73dbf0d-566f-4b2b-95ae-8490c4997f01","topic":"长批处理作业用户：经过前面几个队列部分执行，不会长时间不处理","expanded":true}]},{"id":"c85a4cf4-d481-4149-8a93-ab367fdec2a0","topic":"可能饥饿，抢占式算法","expanded":true}]}]}]}]},{"id":"bf80b678-23f2-47a5-8767-da7c62a27738","topic":"进程同步与互斥","expanded":true,"children":[{"id":"a3ab85c0-80e9-4eb3-ab9c-8ec354df000b","topic":"基本概念","expanded":true,"children":[{"id":"ae1e2a6c-0b1b-42be-97d4-4b93d5fe8b6c","topic":"临界资源","expanded":true,"children":[{"id":"40556109-2f42-4322-b30e-eada92a2de36","topic":"概念：一次只允许一个进程使用的资源","expanded":true},{"id":"3f476779-fda5-4183-a9c5-fd9b12064c96","topic":"访问过程","expanded":true,"children":[{"id":"b06394b3-4ba9-4067-b575-2f5116884deb","topic":"进入区：检查进程是否可以进入临界区（“上锁”）","expanded":true},{"id":"1e9c5473-28fa-4886-831a-d3b17ac57d54","topic":"临界区：可以访问临界资源的代码","expanded":true,"style":{"borderColor":"#EB4D3D"}},{"id":"9fe07461-7073-4d7b-aad7-1b2db78a444d","topic":"退出区：将正在访问临界区的标志清除（“解锁”）","expanded":true},{"id":"4cee1fd0-e608-49f9-a2e1-dcb5d54a49c5","topic":"剩余区：代码中的其余部分","expanded":true}]}]},{"id":"1fb7f7d6-4fbe-4882-a6cb-35ec89b5b200","topic":"同步","expanded":true,"children":[{"id":"894d9ae9-5920-48a9-8646-5179fba38dfc","topic":"直接制约关系，为了完成某任务而建立的多个进程，需要互相通信同步","expanded":true,"children":[{"id":"e4b41306-8acc-4b38-b4e2-ffeecdc34731","topic":"原则","expanded":true,"style":{"borderColor":"#E32C2D"},"children":[{"id":"2461e565-5e24-4703-840f-de91da1b56c1","topic":"空闲让进","expanded":true,"children":[{"id":"6e0d3952-7a4d-4eed-af9b-9d2961fe8dbf","topic":"临界区空闲时，可以允许一个请求进入临界区的进程立即进入临界区","expanded":true}]},{"id":"68940a39-9167-4ace-b964-4e7e96b2861d","topic":"忙则等待","expanded":true,"children":[{"id":"f5347478-f01b-465c-a805-6605010d6266","topic":"已有进程进入临界区后，其他试图进入临界区的进程必须等待","expanded":true}]},{"id":"e6e4fe66-f23d-46fd-80f1-aa5267dbf62d","topic":"有限等待","expanded":true,"children":[{"id":"7294e6bc-b567-4f29-bbda-e5558fe80924","topic":"对于请求访问临界区的进程，在有限时间内进入临界区","expanded":true}]},{"id":"9d79c562-33de-4642-aaa9-0f9b357e6efa","topic":"让权等待","expanded":true,"children":[{"id":"8f6fe8f8-848d-4f4b-97ca-edc6121c7b70","topic":"进程不能进入临界区的时候，应当立即释放处理机","expanded":true,"children":[{"id":"0092074f-008f-420e-9f30-a19ef8a5b4ea","topic":"不是必须遵循","expanded":true,"style":{"borderColor":"#EB4D3D"}}]}]}]}]}]},{"id":"10842593-2144-4f8e-87bf-c51a0a26c530","topic":"互斥","expanded":true,"children":[{"id":"e7fa4e09-fa16-4d4e-8f6b-d5f18f232cec","topic":"间接制约关系，当一个进程访问临界资源时，其他进程不能访问","expanded":true,"children":[{"id":"78e8ec06-22e6-4414-94b7-58cc2e8a2e1d","topic":"共享缓冲区一定是互斥的","expanded":true,"children":[{"id":"ee0d18da-3d02-4d79-87a8-8b4114aa38e5","topic":"可重入编码：纯代码，不会修改任何数据","expanded":true}]}]}]}]},{"id":"f0484e64-2772-48ac-a810-708a00c20d80","topic":"实现临界区互斥的基本方法","expanded":true,"style":{"borderColor":"#FF9F00","branchColor":"#EA8ABA"},"children":[{"id":"07c38b66-cb85-403a-8059-c9520ebda83b","topic":"软件实现方法","expanded":true,"children":[{"id":"2b3156ad-2e18-482e-af9a-4b9d68d37d73","topic":"单标志法","expanded":true,"children":[{"id":"f10aa44c-6a39-412d-9c52-d253fd6adda0","topic":"单标志法伪代码","expanded":true,"children":[{"id":"39905c8e-8429-4c4a-8d1f-e34e9a346322","topic":"仅交替进入，若A轮到不用，B也不能","expanded":true},{"id":"1dac1c0e-83dd-43ea-b037-a4fdcda5e0f7","topic":"违背“空闲让进”","expanded":true}],"code":{"lang":"c","code":"int turn = 0; // 允许进入临界区的进程号（“谦让”）\n\n// P0 进程：\nwhile (turn != 0);     // ① 进入区\ncritical section;      // ② 临界区\nturn = 1;              // ③ 退出区\nremainder section;     // ④ 剩余区\n\n// P1 进程：\nwhile (turn != 1);     // ⑤ 进入区\ncritical section;      // ⑥ 临界区\nturn = 0;              // ⑦ 退出区\nremainder section;     // ⑧ 剩余区","tokens":[[{"text":"int","darkColor":"#74CBC4"},{"text":" turn ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"0","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":" // 允许进入临界区的进程号（“谦让”）","darkColor":"#908B7E"}],[{"text":" "}],[{"text":"// P0 进程：","darkColor":"#908B7E"}],[{"text":"while","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"turn ","darkColor":"#DEDBD2"},{"text":"!=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"0","darkColor":"#E2B159"},{"text":");","darkColor":"#BAB5A8"},{"text":"     // ① 进入区","darkColor":"#908B7E"}],[{"text":"critical section","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"      // ② 临界区","darkColor":"#908B7E"}],[{"text":"turn ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"1","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"              // ③ 退出区","darkColor":"#908B7E"}],[{"text":"remainder section","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"     // ④ 剩余区","darkColor":"#908B7E"}],[{"text":" "}],[{"text":"// P1 进程：","darkColor":"#908B7E"}],[{"text":"while","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"turn ","darkColor":"#DEDBD2"},{"text":"!=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"1","darkColor":"#E2B159"},{"text":");","darkColor":"#BAB5A8"},{"text":"     // ⑤ 进入区","darkColor":"#908B7E"}],[{"text":"critical section","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"      // ⑥ 临界区","darkColor":"#908B7E"}],[{"text":"turn ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"0","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"              // ⑦ 退出区","darkColor":"#908B7E"}],[{"text":"remainder section","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"     // ⑧ 剩余区","darkColor":"#908B7E"}]]}}]},{"id":"5650c874-8848-490d-a322-9b00fb1fe541","topic":"双标志法先检查","expanded":true,"children":[{"id":"6a73b322-ef4c-497a-972b-74cbd1851681","topic":"双标志法先检查伪代码","expanded":true,"children":[{"id":"f6d39891-5d1a-4e9b-adb3-bf55ea516abd","topic":"1、2未经上锁，非一气呵成","expanded":true},{"id":"0c19c5fb-be3e-453e-8c27-b10e352ed01a","topic":"违背“忙则等待”","expanded":true}],"note":"算法思想：设置一个布尔型数组 flag[]，数组中各个元素用来标记各进程想进入临界区的意愿，比如“flag[0] = true”意味着 0 号进程 P0 现在想要进入临界区。每个进程在进入临界区之前先检查当前有没有别的进程想进入临界区，如果没有，则把自身对应的标志 flag[i] 设为 true，之后开始访问临界区。","code":{"lang":"c","code":"// 表示进入临界区意愿的数组（“表达意愿”）\nbool flag[2];\nflag[0] = false;\nflag[1] = false; // 初始都不想进入临界区\n\n// P0 进程：\nwhile (flag[1]);   // ① 进入区：若 P1 想进则等待\nflag[0] = true;    // ② 标记为 P0 想要进入\ncritical section;  // ③ 访问临界区\nflag[0] = false;   // ④ 修改标记为不想使用\nremainder section;\n\n// P1 进程：\nwhile (flag[0]);   // ⑤ 进入区：若 P0 想进则等待\nflag[1] = true;    // ⑥ 标记为 P1 想要进入\ncritical section;  // ⑦ 访问临界区\nflag[1] = false;   // ⑧ 修改标记为不想使用\nremainder section;","tokens":[[{"text":"// 表示进入临界区意愿的数组（“表达意愿”）","darkColor":"#908B7E"}],[{"text":"bool","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"2","darkColor":"#E2B159"},{"text":"];","darkColor":"#BAB5A8"}],[{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"0","darkColor":"#E2B159"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"false","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"}],[{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"1","darkColor":"#E2B159"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"false","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":" // 初始都不想进入临界区","darkColor":"#908B7E"}],[{"text":" "}],[{"text":"// P0 进程：","darkColor":"#908B7E"}],[{"text":"while","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"1","darkColor":"#E2B159"},{"text":"]);","darkColor":"#BAB5A8"},{"text":"   // ① 进入区：若 P1 想进则等待","darkColor":"#908B7E"}],[{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"0","darkColor":"#E2B159"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"true","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"    // ② 标记为 P0 想要进入","darkColor":"#908B7E"}],[{"text":"critical section","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"  // ③ 访问临界区","darkColor":"#908B7E"}],[{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"0","darkColor":"#E2B159"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"false","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"   // ④ 修改标记为不想使用","darkColor":"#908B7E"}],[{"text":"remainder section","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}],[{"text":" "}],[{"text":"// P1 进程：","darkColor":"#908B7E"}],[{"text":"while","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"0","darkColor":"#E2B159"},{"text":"]);","darkColor":"#BAB5A8"},{"text":"   // ⑤ 进入区：若 P0 想进则等待","darkColor":"#908B7E"}],[{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"1","darkColor":"#E2B159"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"true","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"    // ⑥ 标记为 P1 想要进入","darkColor":"#908B7E"}],[{"text":"critical section","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"  // ⑦ 访问临界区","darkColor":"#908B7E"}],[{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"1","darkColor":"#E2B159"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"false","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"   // ⑧ 修改标记为不想使用","darkColor":"#908B7E"}],[{"text":"remainder section","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}]]}}]},{"id":"e20b2c37-75a0-4f4e-8257-e930b8c5505f","topic":"双标志法后检查","expanded":true,"children":[{"id":"9c12ea3d-37ec-42a1-b070-34e7b39b627f","topic":"双标志法后检查伪代码","expanded":true,"children":[{"id":"8ce95113-8eeb-4bab-b6cf-6faf81071858","topic":"同理未一气呵成，违背了“空闲让进”和“有限等待”，长期会产生饥饿","expanded":true}],"note":"算法思想：双标志先检查法的改版。前一个算法的问题是先“检查”后“上锁”，但是这两个操作又无法一气呵成，因此导致了两个进程同时进入临界区的问题。因此，人们又想到先“上锁”后“检查”的方法，来避免上述问题。","code":{"lang":"c","code":"// 表示进入临界区意愿的数组（“表达意愿”）\nbool flag[2];\nflag[0] = false;\nflag[1] = false; // 初始都不想进入临界区\n\n// P0 进程：\nflag[0] = true;    // ① 标记为 P0 想要进入\nwhile (flag[1]);   // ② 若 P1 也想进则循环等待\ncritical section;  // ③ 访问临界区\nflag[0] = false;   // ④ 修改标记为不想使用\nremainder section;\n\n// P1 进程：\nflag[1] = true;    // ⑤ 标记为 P1 想要进入\nwhile (flag[0]);   // ⑥ 若 P0 也想进则循环等待\ncritical section;  // ⑦ 访问临界区\nflag[1] = false;   // ⑧ 修改标记为不想使用\nremainder section;","tokens":[[{"text":"// 表示进入临界区意愿的数组（“表达意愿”）","darkColor":"#908B7E"}],[{"text":"bool","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"2","darkColor":"#E2B159"},{"text":"];","darkColor":"#BAB5A8"}],[{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"0","darkColor":"#E2B159"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"false","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"}],[{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"1","darkColor":"#E2B159"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"false","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":" // 初始都不想进入临界区","darkColor":"#908B7E"}],[{"text":" "}],[{"text":"// P0 进程：","darkColor":"#908B7E"}],[{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"0","darkColor":"#E2B159"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"true","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"    // ① 标记为 P0 想要进入","darkColor":"#908B7E"}],[{"text":"while","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"1","darkColor":"#E2B159"},{"text":"]);","darkColor":"#BAB5A8"},{"text":"   // ② 若 P1 也想进则循环等待","darkColor":"#908B7E"}],[{"text":"critical section","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"  // ③ 访问临界区","darkColor":"#908B7E"}],[{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"0","darkColor":"#E2B159"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"false","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"   // ④ 修改标记为不想使用","darkColor":"#908B7E"}],[{"text":"remainder section","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}],[{"text":" "}],[{"text":"// P1 进程：","darkColor":"#908B7E"}],[{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"1","darkColor":"#E2B159"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"true","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"    // ⑤ 标记为 P1 想要进入","darkColor":"#908B7E"}],[{"text":"while","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"0","darkColor":"#E2B159"},{"text":"]);","darkColor":"#BAB5A8"},{"text":"   // ⑥ 若 P0 也想进则循环等待","darkColor":"#908B7E"}],[{"text":"critical section","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"  // ⑦ 访问临界区","darkColor":"#908B7E"}],[{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"1","darkColor":"#E2B159"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"false","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"   // ⑧ 修改标记为不想使用","darkColor":"#908B7E"}],[{"text":"remainder section","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}]]}}]},{"id":"8ad7785d-fbb8-47cd-ba76-342fbdf1aa55","topic":"皮特森算法","expanded":true,"children":[{"id":"cb2d3b4e-09c7-4889-b803-20c16f50e850","topic":"Peterson 算法伪代码","expanded":true,"children":[{"id":"6bc0ebfc-d35f-4501-aa2b-d8a3bc30a853","topic":"新增标志位，表谦让，最后一个谦让turn=0，则失去机会","expanded":true},{"id":"ad0f01a0-281b-4653-ba2b-04166c0a54bf","topic":"未遵循“让权等待”","expanded":true}],"note":"算法思想：结合双标志法、单标志法的思想。如果双方都争着想进入临界区，那可以让进程尝试“孔融让梨”（谦让）。进入区三步：1. 主动争取；2. 主动谦让；3. 检查对方是否也想使用，且最后一次是不是自己说了“客气话”。","code":{"lang":"c","code":"bool flag[2]; // 意愿数组，初始值都是 false\nint turn = 0; // 优先让哪个进程进入（“谦让”）\n\n// P0 进程：\nflag[0] = true;               // ① 主动争取\nturn = 1;                     // ② 主动谦让\n// ③ 对方想进且最后是自己“让梨”，则等待\nwhile (flag[1] && turn == 1);\ncritical section;             // ④ 访问临界区\nflag[0] = false;              // ⑤ 退出临界区\nremainder section;\n\n// P1 进程：\nflag[1] = true;               // ⑥ 表达意愿\nturn = 0;                     // ⑦ 优先让对方\n// ⑧ 对方想进且最后是自己“让梨”，则等待\nwhile (flag[0] && turn == 0);\ncritical section;             // ⑨ 访问临界区\nflag[1] = false;              // ⑩ 不再访问\nremainder section;","tokens":[[{"text":"bool","darkColor":"#74CBC4"},{"text":" ","darkColor":"#DEDBD2"},{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"2","darkColor":"#E2B159"},{"text":"];","darkColor":"#BAB5A8"},{"text":" // 意愿数组，初始值都是 false","darkColor":"#908B7E"}],[{"text":"int","darkColor":"#74CBC4"},{"text":" turn ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"0","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":" // 优先让哪个进程进入（“谦让”）","darkColor":"#908B7E"}],[{"text":" "}],[{"text":"// P0 进程：","darkColor":"#908B7E"}],[{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"0","darkColor":"#E2B159"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"true","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"               // ① 主动争取","darkColor":"#908B7E"}],[{"text":"turn ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"1","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"                     // ② 主动谦让","darkColor":"#908B7E"}],[{"text":"// ③ 对方想进且最后是自己“让梨”，则等待","darkColor":"#908B7E"}],[{"text":"while","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"1","darkColor":"#E2B159"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"&&","darkColor":"#8EA4E2"},{"text":" turn ","darkColor":"#DEDBD2"},{"text":"==","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"1","darkColor":"#E2B159"},{"text":");","darkColor":"#BAB5A8"}],[{"text":"critical section","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"             // ④ 访问临界区","darkColor":"#908B7E"}],[{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"0","darkColor":"#E2B159"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"false","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"              // ⑤ 退出临界区","darkColor":"#908B7E"}],[{"text":"remainder section","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}],[{"text":" "}],[{"text":"// P1 进程：","darkColor":"#908B7E"}],[{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"1","darkColor":"#E2B159"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"true","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"               // ⑥ 表达意愿","darkColor":"#908B7E"}],[{"text":"turn ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"0","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"                     // ⑦ 优先让对方","darkColor":"#908B7E"}],[{"text":"// ⑧ 对方想进且最后是自己“让梨”，则等待","darkColor":"#908B7E"}],[{"text":"while","darkColor":"#8EA4E2"},{"text":" ","darkColor":"#DEDBD2"},{"text":"(","darkColor":"#BAB5A8"},{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"0","darkColor":"#E2B159"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"&&","darkColor":"#8EA4E2"},{"text":" turn ","darkColor":"#DEDBD2"},{"text":"==","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"0","darkColor":"#E2B159"},{"text":");","darkColor":"#BAB5A8"}],[{"text":"critical section","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"},{"text":"             // ⑨ 访问临界区","darkColor":"#908B7E"}],[{"text":"flag","darkColor":"#EEECE6"},{"text":"[","darkColor":"#BAB5A8"},{"text":"1","darkColor":"#E2B159"},{"text":"]","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"=","darkColor":"#BAB5A8"},{"text":" ","darkColor":"#DEDBD2"},{"text":"false","darkColor":"#E2B159"},{"text":";","darkColor":"#BAB5A8"},{"text":"              // ⑩ 不再访问","darkColor":"#908B7E"}],[{"text":"remainder section","darkColor":"#DEDBD2"},{"text":";","darkColor":"#BAB5A8"}]]}}]}]},{"id":"f88ac424-275b-4693-adfb-da232793c018","topic":"硬件实现方法","expanded":true,"children":[{"id":"97e3ac07-68f2-4281-a7d8-bce186eb23c2","topic":"中断屏蔽法","expanded":true,"children":[{"id":"8e659789-097d-4988-a3e5-053aae718dfd","topic":"对中断屏蔽，关中断防止其他进程进入临界区","expanded":true},{"id":"e68651ea-a081-40a4-ad17-3fae7edbf79a","topic":"不适用于多处理机、仅适用于操作系统内核进程","expanded":true}]},{"id":"99ff6169-5f58-445d-812a-2c3775a733ac","topic":"硬件指令法（TS指令、TSL指令、Swap指令）","expanded":true,"children":[{"id":"351d1cf7-ca7d-4d7a-a677-fc46f0dd3bf9","topic":"硬件逻辑直接实现指令，不会被中断，从而实现进程互斥","expanded":true}]},{"id":"652f819f-6272-4189-ba0d-7fe60be04189","topic":"不能实现让权等待，可能“饥饿”现象","expanded":true}]},{"id":"38f45a6c-6bb1-4a86-b1bd-ad3b2d49fc0b","topic":"以上都未遵循“让权等待”","expanded":true,"style":{"borderColor":"#EB4D3D"}}]},{"id":"98b6c409-dc06-44b2-8131-ebb3d7ef598c","topic":"信号量","expanded":true,"style":{"borderColor":"#FF9F00"},"children":[{"id":"6e11b9e3-72a9-438c-95e5-d17f0d0db1dd","topic":"概念引入","expanded":true,"children":[{"id":"dd993255-a216-4492-b473-da8e38cb166d","topic":"由于进程异步问题，走走停停","expanded":true,"children":[{"id":"f426a3fc-9be2-46cc-9c3b-d81a0231b2fe","topic":"需要发信号来约束","expanded":true,"children":[{"id":"35aaf155-aec7-4a9f-a314-210db01612a4","topic":"信号只能反映有无，引入信号量表达更多消息","expanded":true}]}]}]},{"id":"e2f22002-3e59-4365-af12-9bcf8d42176c","topic":"三种操作：P操作、V操作、创建","expanded":true,"children":[{"id":"6a936989-d5bc-453e-8d60-a808c16b3da8","topic":"PV操作不是系统调用","expanded":true,"style":{"borderColor":"#EB4D3D"}}]},{"id":"cbd5a942-fdc8-4df6-82fa-65da4940532a","topic":"整形信号量","expanded":true,"children":[{"id":"a93ca91b-e353-4793-b269-de2a9fe3d0dc","topic":"定义一个用于表示资源数目的整型量","expanded":true},{"id":"4cb14927-f40a-4108-83c1-5d2ae4c983cb","topic":"没有遵循让权等待，导致进程处于“忙等”状态","expanded":true}]},{"id":"ac37749e-0b35-4379-8e65-5afba9318d4f","topic":"记录形信号量","expanded":true,"children":[{"id":"abb12536-44f5-43fd-b044-e0d9ed8a9a3e","topic":"记录型信号量不存在“忙等”现象，除了需要一个用于代表资源数目的整型变量value外，增加一个进程链表，用于链接所有等待该资源的进程","expanded":true}]},{"id":"fa58a039-6b1a-48e2-8a58-e36a3293c369","topic":"解决一气呵成问题，整形信号量无法“让权等待”，记录型信号量遵循“让权等待”","expanded":true}]},{"id":"cb43a67a-c188-474d-a17c-b76848055b57","topic":"管程（类似于类）","expanded":true,"style":{"borderColor":"#FF9F00"},"children":[{"id":"89fdad61-62b5-48d3-b112-ce625063f556","topic":"概念","expanded":true,"children":[{"id":"db30ff88-9558-4af5-971b-c5d03936f13d","topic":"一组数据以及定义在这组数据上的对这组数据的操作组成的软件模块，这组操作能初始化并改变管程中数据和同步进程","expanded":true}]},{"id":"cf80c991-0c37-4374-af2d-bbd564ec0341","topic":"组成","expanded":true,"children":[{"id":"64ee3eb0-e3b7-45c7-b0ff-54425b53ff9d","topic":"局部于管程的共享结构数据说明","expanded":true},{"id":"3d4f1014-740a-4550-97ce-2720bcbf3244","topic":"对该数据结构进行操作的一组过程","expanded":true},{"id":"c09140ab-8af2-43ef-bd43-b3bbc3ccf578","topic":"对局部于管程的共享数据设置初始值的语句","expanded":true}]},{"id":"9b649b98-425b-4435-b405-60d228414846","topic":"基本特征","expanded":true,"children":[{"id":"387752d3-7085-4b56-a479-6563468da638","topic":"局部于管程的数据只能被局部于管程内的过程所访问","expanded":true},{"id":"a6e8dbf2-ba95-4fbb-9909-58be5289f5b8","topic":"一个进程只有通过调用管程内的过程才能进入管程访问共享数据","expanded":true},{"id":"1a836d45-6ce6-4712-8c01-e015cbe9d6cd","topic":"每次仅允许一个进程在管程内执行某一个内部过程（保证互斥性）","expanded":true,"children":[{"id":"4721a867-7a6a-42a7-909d-9d7512eabb7d","topic":"管程中signal操作和V操作有所不同","expanded":true,"children":[{"id":"bb976713-26c7-4f56-afe4-3b57654c42e9","topic":"管程被进程调用，语法范围，无法创建和撤销（静态）","expanded":true}]}]}]}]},{"id":"30a6bc73-6c23-46fd-9643-3f96bc6d180d","topic":"经典同步问题","expanded":true,"style":{"borderColor":"#E32C2D"},"children":[{"id":"15123f16-1074-4240-a72b-3e8479e450c3","topic":"核心","expanded":true,"children":[{"id":"1bed2ba5-b89d-4989-83fe-8d00eb22a32f","topic":"实现互斥","expanded":true,"children":[{"id":"5411b400-e1df-4626-b8c0-9e726561d351","topic":"初值为1，前P后V","expanded":true,"style":{"borderColor":"#EB4D3D"}}]},{"id":"5bacf803-eba0-4313-88cc-81ad7eeae5b7","topic":"实现同步","expanded":true,"children":[{"id":"408acb8f-a001-4452-9ce6-a92f2a118e8b","topic":"期望消息未产生则初值为0，反之为非0正数，前V后P","expanded":true,"style":{"borderColor":"#EB4D3D"}}]},{"id":"0f5f32fe-23cd-4a47-a2aa-e8d09f217e3a","topic":"实现前驱关系","expanded":true},{"id":"5cecee5f-4f82-41fd-977e-541e64279b4c","topic":"以下具体问题，提一下王道的重点思路，可以考前听王道","expanded":true}]},{"id":"54e533d8-4786-476d-a431-5fa7e5dc1664","topic":"生产者-消费者问题","expanded":true},{"id":"f8c5590d-0a89-41f9-a7d6-da42b04143e5","topic":"多生产者-多消费者问题","expanded":true,"children":[{"id":"4889f5ba-d58f-41f1-8395-27ad8822f282","topic":"若盘子数为1，可省去mutex，本身访问互斥","expanded":true}]},{"id":"ee47ed89-2ed8-4352-a5c8-91daeffd1032","topic":"吸烟者问题","expanded":true},{"id":"2ef33129-6929-4c9f-9ec9-0317a9ae1b1d","topic":"读者-写者问题","expanded":true,"children":[{"id":"c2bb0631-345e-47e8-b3a7-084c8bc193a7","topic":"增加P(w)、V(w)使写优先，防止源源不断读者，饥饿问题","expanded":true},{"id":"bc435024-fe73-45b5-b362-9937228dfd18","topic":"增加互斥信号量使count--和if(count==0)一气呵成","expanded":true}]},{"id":"37ef2f16-86dd-44d6-b2fb-ff11514296e2","topic":"哲学家进餐","expanded":true,"children":[{"id":"9ac176b8-95fb-46f3-9d52-455fea526479","topic":"思路一：最多允许四位同时吃饭","expanded":true},{"id":"3f0ac2bb-b421-4bf4-9011-094f8493164a","topic":"思路二：奇数号哲学家先拿左筷子，偶数号相反","expanded":true},{"id":"c46ba10d-a11b-4d71-ab50-8de8ee8a3321","topic":"思路三：仅当哲学家左右能同时拿起筷子时进食（拿筷子的动作加互相信号，一气呵成）","expanded":true}]}]}]},{"id":"034d328a-4a25-45e6-aa3f-223453046859","topic":"死锁","expanded":true,"children":[{"id":"4e267e4c-7d76-4307-98e6-2b288f65c29c","topic":"死锁的概念","expanded":true,"children":[{"id":"63ac7a80-b7e4-46b3-bfa2-137317e8e082","topic":"概念","expanded":true,"children":[{"id":"18e1f73c-76e9-43ed-8bc2-ac36c15ae90c","topic":"两个或两个以上的进程在执行过程中，由于竞争资源而造成的一种阻塞的现象，若无外力作用，它们都将无法推进下去","expanded":true}]},{"id":"cb3ea4a1-b178-43b2-bd35-1d789102ce3f","topic":"死锁产生的原因","expanded":true,"children":[{"id":"9da9e486-2701-420f-a1d9-d9f59aad3716","topic":"系统资源的竞争（不可剥夺资源）","expanded":true},{"id":"bfe7278e-3698-42b2-93cb-146f4af3ae22","topic":"进程推进顺序非法","expanded":true},{"id":"b1b1224a-37ec-41c0-964e-dd009e7853cd","topic":"产生的必要条件（同时满足）","expanded":true,"style":{"borderColor":"#E32C2D"},"children":[{"id":"278cc495-82fd-4ffd-b9de-be4cdb9931df","topic":"互斥条件：进程对分配的资源进行排他性控制","expanded":true},{"id":"75ff3250-a66f-4422-8594-faef12973b8d","topic":"不可剥夺条件：进程获得资源在未使用完之前，不能被其他进程强行夺走","expanded":true},{"id":"84011a4e-bf39-4a04-9d99-d45ac21e7acd","topic":"请求并保持条件：进程已经保持了至少一个资源，提出新的资源请求被阻塞，但是自己已经获得的资源保持不放","expanded":true},{"id":"637a6ac9-d5b1-46bc-a123-4163d75c1e85","topic":"循环等待条件：你等我释放，我等你释放","expanded":true}]}]}]},{"id":"a4ed23a7-40e6-4c2a-a13e-7ab848b84ede","topic":"死锁的处理策略","expanded":true,"style":{"borderColor":"#E32C2D","branchColor":"#00A99D"},"children":[{"id":"76465600-e459-47b6-adb0-2b5c67485648","topic":"死锁预防","expanded":true,"children":[{"id":"b48ed955-5a06-46cc-a943-aaf903961f7c","topic":"破坏互斥条件","expanded":true,"children":[{"id":"2a7c3fc9-3b7b-4e3e-a3c8-10d55b25ca06","topic":"某些资源只能被互斥访问，某些情况下必须保护互斥性","expanded":true}]},{"id":"a5c40f7d-9a8f-473d-b8a0-0afe4f6796f6","topic":"破坏不剥夺条件","expanded":true,"children":[{"id":"58d6a183-b11a-4dae-8264-754e04417452","topic":"释放已经占有的资源（主动，操作系统协助剥夺）","expanded":true}]},{"id":"e863202d-819e-48d4-a459-b95dc5d6f4b2","topic":"破坏请求并保持条件","expanded":true,"children":[{"id":"bde826d6-03a7-4c78-a3a1-b51e7321c54d","topic":"一次性申请完所需要的全部资源（静态分配法）","expanded":true}]},{"id":"3a6fd61e-cde3-41c3-9c40-59633ccf19b3","topic":"破坏循环等待条件","expanded":true,"children":[{"id":"cdfd3431-ead1-46c1-bd5b-3dd3b3ec8276","topic":"采用顺序资源法，对进程进行顺序推进（对进程编号）","expanded":true}]}]},{"id":"2145b377-0eeb-44de-a01c-bdf8ec399364","topic":"死锁避免","expanded":true,"children":[{"id":"d62fbb58-b9bb-4abb-a6a5-0806f40489d6","topic":"系统安全状态","expanded":true,"children":[{"id":"e8096a33-9cb9-490c-9a9e-515593947245","topic":"指系统能按某种推进顺序为每个进程分配其所需的资源，直至满足每个进程对资源的最大需求，每个进程都可顺利完成","expanded":true,"children":[{"id":"8dc0be35-48cc-453e-b6cc-c0fe6a4db4dd","topic":"不能判断是否死锁","expanded":true,"style":{"borderColor":"#EB4D3D"}}]}]},{"id":"8dafbfbf-3553-4986-9ce4-addcc30f2046","topic":"银行家算法","expanded":true,"children":[{"id":"56d87c7f-d140-4eb5-8d83-6c5ca6bc6ba9","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-b92fca01cb7a50.png","width":517.89,"height":117.3},"children":[{"id":"da2b5f59-f129-48d3-a640-c0f166601f86","topic":"概念（三个矩阵图片中从左到右）","expanded":true,"children":[{"id":"8fc3d8fe-49f2-426d-84d8-1e44234bf6bc","topic":"可利用资源向量Available：m个元素的数组，每个元素代表一类可用资源数目","expanded":true},{"id":"31cabdbe-a36f-434f-a324-20ec22d77607","topic":"最大需求矩阵Max：n个进程中每个进程对m类资源最大需求","expanded":true},{"id":"1aeeb7d9-c4ba-490d-a9c0-10270d4f2771","topic":"分配矩阵Allocation：系统中每类资源已经分配给每个进程的数量","expanded":true},{"id":"e062958f-3899-4d33-ad57-5a365f603c68","topic":"需求矩阵Need：表示接下来每个进程最多还要多少资源","expanded":true},{"id":"3275a502-5add-4e27-845e-3bc3815f0427","topic":"矩阵关系：Need=Max-Allocation","expanded":true}]},{"id":"975ac038-c03f-4b55-b32d-50d69dada76b","topic":"执行","expanded":true,"children":[{"id":"eb49772e-345e-4bac-a744-0308206f4772","topic":"判断剩余资源是否能满足需求矩阵中进程，若满足回收已分配资源，继续判断，直到所有资源都被分配完，若无一满足则回溯","expanded":true}]}]}]}]},{"id":"e6e44dad-a81c-485c-9f54-00faafe1bc7c","topic":"死锁的检测和解除","expanded":true,"children":[{"id":"436c09ac-517e-4e7e-8f09-d9c341de5471","topic":"资源分配图","expanded":true,"children":[{"id":"adaf37c7-341f-4e28-b3cb-b4f48807ef5d","topic":"图示","expanded":true,"image":{"src":"https://gastigado.cnies.org/d/BrushUP/mm-1e65216a89288f.png","width":254.33,"height":162},"children":[{"id":"9d5e903c-36f5-4fed-8b60-3a9594f8b8bb","topic":"绿色箭头：资源分配边","expanded":true},{"id":"beb57e90-4dbc-4e1d-99cb-924498275d43","topic":"蓝色箭头：申请资源边","expanded":true},{"id":"bb914002-bdbc-42cd-891e-2bb09a48bc8e","topic":"圈圈为进程、框为一类资源（框内圆点为拥有的资源）","expanded":true}]}]},{"id":"7dfc4ef5-472b-40f7-8c43-0a7cf7724e03","topic":"死锁定理","expanded":true,"children":[{"id":"165a649f-a516-4858-9537-7bb2761aa4e5","topic":"在资源分配图中找到分配满足的进程，然后消去请求边与分配边","expanded":true},{"id":"ddd25e18-57e5-404a-b958-2116a12b0991","topic":"若所有边都可以被消去，则不存在死锁，反之存在死锁","expanded":true}]},{"id":"cde453ac-c46b-4bcf-a54a-e80958bfd441","topic":"死锁解除","expanded":true,"children":[{"id":"96163d15-a453-4f18-9307-a597c4b35b30","topic":"资源剥夺法","expanded":true,"children":[{"id":"68869b91-0624-4ccc-90d8-b832a9e478b0","topic":"挂起某些死锁进程，抢占资源，将这些资源分配给其他死锁进程，但需要防止挂起时间过长","expanded":true}]},{"id":"21f07a39-b5e0-47c6-81d5-419d62d5e977","topic":"撤销进程法","expanded":true,"children":[{"id":"d445a197-6ded-4d48-9828-e2b0a4565d21","topic":"强制撤销部分甚至全部死锁进程，剥夺他们的资源","expanded":true,"children":[{"id":"e68a39b0-2721-48fc-ae60-36626cb25f8c","topic":"选择原则：优先级、已执行时间、还要多久完成、已用资源数、交互式/批处理式","expanded":true,"children":[{"id":"e3f30db7-2cf2-4e72-98d8-1877f6647574","topic":"通常不采用从非死锁进程处抢夺资源","expanded":true,"style":{"borderColor":"#EB4D3D"}}]}]}]},{"id":"9ba846dd-0449-4b13-be11-6893ecb202bc","topic":"进程回退法","expanded":true,"children":[{"id":"d5f57352-8813-425e-a768-5cc0274f8af1","topic":"让一个或者多个进程回退到足以回避死锁的地步，进程回退时自愿释放资源而非被剥夺（要求系统保持进程历史信息，设置还原点）","expanded":true}]}]}]}]},{"id":"82148b1d-281c-48af-b75a-b37a56f3d26a","topic":"死锁、饥饿、死循环的区别","expanded":true,"children":[{"id":"d88ce1e0-27e5-4726-8586-5e84610f6e21","topic":"死锁：各进程相互等待对方手里的资源，导致各进程都阻塞，无法向前推进的现象（操作系统解决）","expanded":true},{"id":"0cfdc583-5e8c-4bb2-8a4a-0db10fa6fdf0","topic":"饥饿：由于长期得不到想要的资源，某进程无法向前推进的现象（操作系统解决）","expanded":true},{"id":"b7b855e0-e812-471f-ae74-74c168c05aa1","topic":"死循环：某进程执行过程中一直跳不出某个循环的现象（程序员解决）","expanded":true}]}]}]}}