From 91e0a2fe55a5a79c8a1cd4371297207dc2e51685 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Thu, 10 Apr 2025 21:45:33 +0800 Subject: docs(cards): new card Former-commit-id: af27ef043a2c19f0e9c56164e806b15978fa6624 --- "content/cards/\345\216\237\350\257\255.md" | 18 ++++++++++++++++++ "content/\345\216\237\350\257\255.md" | 16 ---------------- 2 files changed, 18 insertions(+), 16 deletions(-) create mode 100644 "content/cards/\345\216\237\350\257\255.md" delete mode 100644 "content/\345\216\237\350\257\255.md" (limited to 'content') diff --git "a/content/cards/\345\216\237\350\257\255.md" "b/content/cards/\345\216\237\350\257\255.md" new file mode 100644 index 00000000..40bc3fe2 --- /dev/null +++ "b/content/cards/\345\216\237\350\257\255.md" @@ -0,0 +1,18 @@ +--- +title: 原语 +tags: + - 计算机 + - 操作系统 +date: 2025-04-10T21:45:00 +draft: false +--- +原语(primitive)是计算机中**不可被中断**的一段机器指令,常见于**操作系统**中的进程调度,用于实现同步(synchronization)。一个操作需要用原语实现,常常是因为这种操作一旦被中断,就会发生非常严重的错误,所以不允许中断。 + +原语的「原」可以理解为「原子」(Atom),执行原语就是在执行一个原子操作(atomic action)。 + +要实现原语,有两种方式: + +1. **禁用中断**,这种操作在多核处理器上非常低效。 +2. **专用机器指令**,在多核处理器上实现同步,需要在硬件层面实现一套能够进行原子操作的机器指令(atomic instructions);例如 `test-and-set` 用于操作内存中的单个字(word),`compare-and-swap` 用于交换内存中的两个字。 + +Sources: 《操作系统 精髓与设计原理》[美] WILLIAM STALLINGS、[Synchronization (computer science) - Wikipedia](https://en.wikipedia.org/wiki/Synchronization_(computer_science)) \ No newline at end of file diff --git "a/content/\345\216\237\350\257\255.md" "b/content/\345\216\237\350\257\255.md" deleted file mode 100644 index cd11d92f..00000000 --- "a/content/\345\216\237\350\257\255.md" +++ /dev/null @@ -1,16 +0,0 @@ ---- -title: 原语 -tags: - - 计算机 -date: 2025-04-09 17:25:18 -draft: true ---- -原语(primitive)是计算机中**不可被中断**的一段机器指令,常见于**操作系统**中的进程调度。一个操作需要用原语实现,常常是因为这种操作一旦被中断,就会发生非常严重的错误,所以不允许中断。 - -原语的「原」可以理解为「原子」(Atom),执行原语就是在执行一个原子操作(atomic action)。 - -要实现原语,有两种方式: - -1. 禁用中断。 - -Sources: 《操作系统 精髓与设计原理》[美] WILLIAM STALLINGS \ No newline at end of file -- cgit v1.2.3