COMPUTATIONAL THINKING | THINKING CONCURRENTLY
SECTION 1 | IDENTIFY THE PARTS OF A SOLUTION THAT COULD BE IMPLEMENTED CONCURRENTLY
Concurrency refers to the ability of a system to handle multiple tasks at the same time. In the context of programming, it is related to the decomposition of a problem into parts that can be executed independently and potentially in parallel.
When discussing concurrency within a solution, you should identify which parts of a system can operate simultaneously without depending on the outputs or states of others. These parts can be executed in parallel (at the exact same time, e.g., in a multi-core processor) or pseudo-parallel via techniques like time-slicing in single-core processors.
Difference between Concurrency and Parallelism.
Benefits and Challenges of Concurrency:
-
Faster execution, better resource use, improved performance.
-
Complexity in design, potential for deadlocks, and race conditions.
When looking if your program requires the use of concurrency you should.
-
Identifying independent tasks: Tasks that do not depend on each other for data or resources.
-
Determining data dependencies: Understanding which processes require data from others to operate.
When applying concurrency to your program:
-
Use of threads, processes, and asynchronous executions.
-
Consider synchronization: Ensuring data consistency and integrity during concurrent executions.
Example scenario: Library management system
Concurrent Part
-
User Management & Book Management: While one user is managing their account or borrowing books, another user can concurrently access and navigate through the available books.
-
Database Access: Multiple users should be able to access, read, and modify (if permitted) different parts of the database at the same time.
Non-concurrent Part
-
Payment Transaction: Often, payment gateways are not designed to handle concurrent transactions from the same user account to prevent fraud or data inconsistencies.
SECTION 2 | DESCRIBE HOW CONCURRENT PROCESSING CAN BE USED TO SOLVE A PROBLEM
Concurrency in computing refers to the ability of a system to handle multiple tasks at the same time. This doesn’t always imply that the tasks are being executed simultaneously. Instead, tasks can be distributed across available resources and managed in a way that allows them to make collective progress. Concurrent processing can boost efficiency, enhance performance, and sometimes simplify program structure. Executing multiple tasks or processes in overlapping time periods, either truly simultaneously (parallel processing) or seemingly simultaneously (as in multitasking). The methods below are popular methods used to achieve concurrency.
Threads: The smallest unit that can be scheduled in an operating system. Threads within a process share the same data space.
Parallelism: Truly simultaneous task execution, often achieved through multi-core processors.
Asynchrony: The state of not being synchronized, meaning tasks are executed independently and without waiting for other tasks to complete.
Imagine you program needs to perform a large calculation, with concurrent processing it can do this in the background while other tasks are still carried out or large data sets can be split and processed concurrently.
-
Parallel Data Processing: Utilize parallelism for large data set processing where data can be split and processed concurrently, reducing computation time.
-
Responsive User Interfaces: Manage UI interactions in one thread and process background tasks like data loading and computation in another, ensuring that the UI remains responsive.
This helps optimize the use of resources and enhance the user experience.
Some of the drawbacks and challenges of concurrent process are:
-
Synchronization Issues: Manage shared resources and ensure that concurrent tasks don’t interfere with each other, avoiding data inconsistencies or corruption.
-
Deadlocks: Prevent scenarios where concurrent tasks wait for each other to release resources, leading to a system halt.
-
Task Coordination: Ensure that tasks are coordinated and managed efficiently to optimize resource utilization.
Concurrent processing is pivotal in optimizing problem-solving strategies, especially in scenarios involving considerable computational load or the necessity of handling multiple tasks or requests simultaneously. Though it introduces complexity in task management and resource sharing, the resulting enhancement in performance and resource utilization can be invaluable.
SECTION 3 | EVALUATE THE DECISION TO USE CONCURRENT PROCESSING IN SOLVING A PROBLEM
The evaluation to implement concurrent processing involves a meticulous analysis of the problem domain, anticipated benefits, associated challenges, and wider implications on the technical and non-technical aspects of project development. This holistic approach ensures that the solution derived is not only technically robust but also resource-efficient, scalable, and justifiable in the context of the associated development efforts and costs.
Key Considerations in Decision Making
-
Is the problem genuinely conducive to a concurrent solution?
-
Can tasks be broken down into smaller, independent sub-tasks?
Complexity vs. Gain
-
Does the performance gain or user experience enhancement justify the added complexity?
-
Will concurrency utilize system resources (CPU, memory) more efficiently?
-
Are the additional development time and potential increase in costs justified?
-
Will concurrency provide a scalable solution as the problem or user base grows?
Are the challenges of concurrency worth it
-
Concurrent programs often struggle with data dependencies. Evaluating how data is shared among tasks is crucial.
-
Frequent need for synchronization, like locking shared resources to prevent concurrent modifications, can offset the gains of concurrent execution.
Concurrent programs are typically more challenging to test and debug. Thus, evaluating whether the team has the requisite skills and tools is pivotal.