215-thinking-concurrently-elements-of-computational-thinking Flashcards
Thinking concurrently
- spotting dependency patterns and related parts of problems where concurrent processing can be applied/process at same time
- tasks are broken down into sub tasks
-situation where you want carrying out more than one task at a given time
concurrent processing pros
- possibly find solution faster, less time waiting as other tasks can be completed while perhaps waiting for user input
- increase program throughput (processing in a given time)
- availability of services e.g shouldnt have long running tasks delaying short ones
- reactive programming, controllability
concurrent processing cons
- memory intensive, threads expensive
- if designed poorly can actually run slower than sequential counterparts even with multiple CPU cores
-More difficult to debug and program - deadlock tasks indefinitely wait for each other: can occur more easily with many concurrent occurring at once
- overhead switching and coordinating threads/communication between concurrent tasks
- not all tasks are suited
- longer to complete if large number of tasks involved concurrently and difficult to track to ensure consistent state of a program not corrupted
parallel vs concurrent processing
concurrent single processor is switching between separate tasks so that all tasks appear to be being processed at the same time.
concurrency
- can support two or more tasks in progress at same time, not necessarily simultaneously but creates the illusion when they’re being executed sequentially
- several running processes given processor time slice.
- carrying out more than one task at a given time
single threaded vs multi threaded
Threads allow the processor to perform multiple tasks at the same time making the tasks faster. And also making the computer capable of multitasking. Due to threads only you are able to browse the web as well as listen to music simultaneously.
threads handle a specific task/ a thread opened to handle all the tasks of a specific application
single: linear execution flow, instructions one after the other, in a predetermined sequential path, executing functions in order and branching when necessary
multi: can have multiple threads of execution running concurrently, each thread has a separate flow and execution, multiple parts of the program can execute simultaneously
Reactive programming
User should be able to interact with applications while other tasks are running in the background.
all OSes are built like this to support concurrency
Parallelism vs concurrency
concurrent is support actions in progress at the same time. dealing with lots of things at once.
-parallel is actions executing. simultaneously. doing lots of things at once.
controllability
task that might require certain preconditions to proceed could be suspended and then wait until those preconditions are met before resuming execution transparently