You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Concurrent processing means multiple tasks are in progress at the same time. In OCR H446, you need to understand the benefits and challenges of concurrency, including race conditions, deadlock, and shared resource management. Thinking concurrently means identifying which parts of a problem can be solved simultaneously.
| Term | Definition |
|---|---|
| Concurrent | Multiple tasks are in progress during the same time period (may not be executing at exactly the same instant) |
| Parallel | Multiple tasks are executing at exactly the same instant (requires multiple processors/cores) |
| Sequential | Tasks execute one after another |
Important distinction: Concurrency is about managing multiple tasks; parallelism is about executing them simultaneously. A single-core processor can handle concurrency (by switching between tasks) but not true parallelism.
Sequential: Task A ------> Task B ------> Task C ------>
Concurrent: Task A --> Task B --> Task A --> Task C --> Task B -->
Parallel: Task A ------>
Task B ------>
Task C ------>
| Benefit | Explanation | Example |
|---|---|---|
| Faster overall completion | Multiple tasks progress simultaneously | A web server handles thousands of requests at once instead of one at a time |
| Better resource utilisation | While one task waits (e.g., for I/O), another can use the CPU | While waiting for a file to load, the program processes user input |
| Improved responsiveness | The user interface remains responsive while background tasks run | A word processor saves a document while the user continues typing |
| Scalability | Adding more processors/cores increases throughput | A multi-core server handles more traffic |
Not all tasks can run concurrently. The key question is: are the tasks independent?
| Scenario | Can be concurrent? | Why? |
|---|---|---|
| Downloading 3 files from the internet | Yes | Each download is independent |
| Computing A + B, then (A + B) * C | No | The multiplication depends on the addition result |
| Rendering different sections of an image | Yes | Each section is independent |
| Reading from a file, then writing to the same file | No (must be sequential) | Writing before reading is complete would corrupt data |
| Searching different parts of a database | Yes | Each search is independent |
Key Term: Tasks are independent if neither requires the output of the other. Independent tasks can safely run concurrently.
A race condition occurs when the outcome of a program depends on the timing or order of concurrent operations, and that order is not guaranteed.
Example — Bank account:
Two processes try to withdraw from the same account (balance = 100):
Process A: Read balance (100)
Process B: Read balance (100)
Process A: Withdraw 80, write balance (100 - 80 = 20)
Process B: Withdraw 60, write balance (100 - 60 = 40)
Final balance: 40. But 80 + 60 = 140 was withdrawn from an account with only 100. This is a race condition — Process B read the balance before Process A's write was complete.
Correct result: Process A should have completed fully before Process B started, or a locking mechanism should have prevented simultaneous access.
Deadlock occurs when two or more processes are each waiting for the other to release a resource, so none of them can proceed.
Conditions for deadlock (all four must be present):
| Condition | Description |
|---|---|
| Mutual exclusion | At least one resource is non-shareable (only one process can use it at a time) |
| Hold and wait | A process holds one resource while waiting for another |
| No pre-emption | Resources cannot be forcibly taken from a process |
| Circular wait | Process A waits for Process B, which waits for Process A |
Classic example — Dining Philosophers:
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.