Conflict in Computer Science | 计算机科学中的冲突

📚 Conflict in Computer Science | 计算机科学中的冲突

In A-Level Computer Science, the term ‘conflict’ describes any situation in which competing operations, processes, transactions, interrupts or devices attempt to access the same resource or perform incompatible actions at the same time. Conflicts matter because they can corrupt data, create non-deterministic behaviour, slow down a system, or even cause complete deadlock. This article explains the main conflict types covered by the Edexcel specification and the techniques used to detect, prevent or resolve them.

在 A-Level 计算机科学中,”冲突” 一词描述的是相互竞争的操作、进程、事务、中断或设备试图同时访问同一资源或执行不兼容操作的情况。冲突之所以重要,是因为它们可能破坏数据、产生不确定行为、降低系统速度,甚至造成完全死锁。本文解释 Edexcel 考试大纲中涉及的主要冲突类型,以及用于检测、预防或解决这些冲突的技术。

1. What Is Conflict in Computing? | 什么是计算中的冲突

A computing conflict happens when two or more active agents require the same resource at the same time, or when their actions are mutually incompatible. Examples include two processes writing to the same file, two transactions updating the same database row, two devices raising the same interrupt, and two network stations transmitting on a shared cable. The key idea is that the final state of the system depends on whose action wins, or whether the system manages the competition safely.

计算中的冲突发生在两个或多个活动主体同时需要同一资源,或者它们的操作互不兼容时。例如两个进程写入同一文件、两个事务更新同一数据库行、两个设备触发同一中断、两个网络站点在共享电缆上同时发送数据。关键点在于系统的最终状态取决于谁的操作获胜,或者系统是否安全地管理了竞争。

At A-Level, conflict questions usually fall into three areas: concurrency and operating systems, databases and transactions, and hardware or network communication. You need to identify the type of conflict, explain how it arises, describe the consequence, and outline a control mechanism such as locking, arbitration or collision detection.

在 A-Level 中,冲突类题目通常分为三个领域:并发与操作系统、数据库与事务、硬件或网络通信。你需要识别冲突类型、解释它如何产生、描述后果,并概述一种控制机制,例如锁定、仲裁或冲突检测。


2. Resource Contention and Deadlock | 资源竞争与死锁

Operating systems manage several competing processes; each process may need CPU time, memory blocks, file handles or I/O devices. A resource conflict occurs when two or more processes demand the same scarce resource at the same time. The scheduler and resource manager must decide which process receives the resource and for how long.

操作系统管理多个相互竞争的进程;每个进程可能需要 CPU 时间、内存块、文件句柄或 I/O 设备。当两个或多个进程同时要求同一稀缺资源时,就会发生资源冲突。调度程序和资源管理器必须决定哪个进程获得资源以及获得多长时间。

Deadlock is the most severe resource conflict. It happens when a set of processes is permanently blocked because each process holds a resource the others need. The four Coffman conditions are mutual exclusion, hold and wait, no preemption and circular wait. If all four conditions hold, deadlock is possible. The system cannot make progress without intervention, such as killing a process or forcing a resource release.

死锁是最严重的资源冲突。当一组进程永久阻塞,因为每个进程都持有其他进程所需的资源时,就会发生死锁。四个 Coffman 条件为:互斥、占有并等待、不可抢占和循环等待。如果四个条件同时成立,死锁就可能发生。系统必须通过终止进程或强制释放资源等干预手段才能继续前进。


3. Race Conditions in Concurrent Programs | 并发程序中的竞态条件

A race condition is a conflict between threads or processes over shared data rather than a physical resource. The final value depends on the order in which instructions are interleaved. For example, if two processes execute x ← x + 1 on a shared variable x, both may read the original value before either writes, so one increment is lost.

竞态条件是线程或进程之间针对共享数据而非物理资源的冲突。最终值取决于指令交错执行的顺序。例如,如果两个进程对共享变量 x 执行 x ← x + 1,两个进程可能都在写入之前读取原始值,导致一次递增丢失。

x = 0; Thread A: x ← x + 1; Thread B: x ← x + 1; possible final x = 1

Race conditions are particularly dangerous in banking, flight booking and file systems, where a lost update can change the meaning of a transaction. Because scheduling is non-deterministic, the bug may appear only occasionally, making it difficult to reproduce during testing.

竞态条件在银行、航班预订和文件系统中尤其危险,丢失更新可能改变事务的含义。由于调度是不确定的,这种错误可能只是偶尔出现,因此测试时很难复现。


4. Mutual Exclusion and Critical Sections | 互斥与临界区

To prevent race conditions, code that accesses a shared resource must be placed in a critical section. Mutual exclusion ensures that only one process or thread can be inside its critical section at a time. This can be implemented using locks, semaphores, monitors or atomic instructions such as test-and-set.

为了防止竞态条件,访问共享资源的代码必须放在临界区中。互斥确保同一时刻只有一个进程或线程可以进入其临界区。这可以通过锁、信号量、监视器或原子指令(如 test-and-set)来实现。

A correct mutual exclusion solution must satisfy three properties: mutual exclusion, progress and bounded waiting. Mutual exclusion prevents simultaneous access; progress ensures that a process outside its critical section cannot block others forever; bounded waiting guarantees that no process waits indefinitely.

正确的互斥解决方案必须满足三个特性:互斥、进展和有限等待。互斥防止同时访问;进展确保不在临界区内的进程不会永远阻塞其他进程;有限等待保证任何进程都不会无限期等待。


5. Database Transaction Conflicts | 数据库事务冲突

A database transaction is a logical unit of work that should be atomic and isolated. When the DBMS interleaves operations from multiple transactions to increase throughput, conflicts can arise if two transactions access the same data item and at least one writes. The isolation property must prevent these conflicts from making the database inconsistent.

数据库事务是一个应当具有原子性和隔离性的逻辑工作单元。当 DBMS 为了提高吞吐量而交错执行多个事务的操作时,如果两个事务访问同一数据项且至少有一个执行写操作,就可能产生冲突。隔离性必须防止这些冲突使数据库变得不一致。

Three classic anomalies are tested at A-Level: lost update, dirty read and unrepeatable read. They are introduced here and compared in the next section. The DBMS can use locks or timestamp ordering to keep transactions isolated.

A-Level 考试中会考查三种经典异常:丢失更新、脏读和不可重复读。这里先进行介绍,下一节再作比较。DBMS 可以使用锁或时间戳排序来保持事务隔离。


6. Lost Update, Dirty Read and Unrepeatable Read | 丢失更新、脏读和不可重复读

These three anomalies are the most common consequences of database transaction conflicts. Each one breaks the isolation property in a different way, so it is important to recognise their definitions and be able to give a short example.

这三种异常是数据库事务冲突最常见的后果。它们以不同方式破坏隔离性,因此必须能够识别其定义并给出简单示例。

Published by TutorHao | A-Level Computer Science Revision Series | aleveler.com

更多咨询请联系16621398022(同微信)

Comments

屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from aleveler.com

Subscribe now to keep reading and get access to the full archive.

Continue reading

Anomaly | 异常 Description | 描述 Example | 示例
Lost update | 丢失更新 Two transactions read the same value and then both write; the first write is overwritten by the second. T₁ and T₂ both read A = 10. T₁ writes A = 11, then T₂ writes A = 12. The update from T₁ is lost.
Dirty read | 脏读 A transaction reads uncommitted data from another transaction, and that transaction later aborts. T₁ writes A = 20. T₂ reads A = 20. T₁ aborts. T₂ has read a value that never committed.
Unrepeatable read | 不可重复读 A transaction reads the same row twice, but another transaction modifies and commits in between, so the two reads return different values.