官术网_书友最值得收藏!

Hardware

The simplest hardware-based implementation on a uniprocessor (single processor core), non-SMT system is to disable interrupts, and thus, prevent the task from being changed. More commonly, a so-called busy-wait principle is employed. This is the basic principle behind a mutex--due to how the processor fetches data, only one task can obtain and read/write an atomic value in the shared memory, meaning, a variable sized the same (or smaller) as the CPU's registers. This is further detailed in Chapter 8, Atomic Operations - Working with the Hardware.

When our code tries to lock a mutex, what this does is read the value of such an atomic section of memory, and try to set it to its locked value. Since this is a single operation, only one task can change the value at any given time. Other tasks will have to wait until they can gain access in this busy-wait cycle, as shown in this diagram:

主站蜘蛛池模板: 喜德县| 神池县| 乌兰察布市| 惠水县| 贵港市| 大冶市| 呼伦贝尔市| 清涧县| 资源县| 左权县| 宜良县| 茌平县| 秦安县| 瑞昌市| 伊春市| 皋兰县| 福泉市| 西乡县| 庄河市| 浦城县| 隆子县| 容城县| 鸡西市| 天长市| 广东省| 那坡县| 望都县| 时尚| 武邑县| 台北市| 永定县| 玉溪市| 福泉市| 许昌县| 确山县| 惠州市| 安新县| 富平县| 稻城县| 新田县| 芦溪县|