2.1.5 - Thinking Concurrently Flashcards
What is concurrency?
An application is making progress on more than one task at the same time (concurrently).
What is concurrent processing?
Concurrent processing means different tasks are given slices of processor time, to give the illusion that tasks are being performed simultaneously.
What is meant by thinking concurrently?
Thinking concurrently is a skill which involves working out which parts of a program can be developed to take place/be processed at the same time. You must consider which parts are dependent on others (these can’t be done concurrently).
Benefit of concurrent programming
- Number of tasks completed in a given time is increased.
- Less time is wasted waiting for an input/user interaction as other tasks can be completed.
- A user can interact with applications whilst other tasks are running in the background e.g. working on a presentation whilst downloading a file.
- A long-running task won’t delay short-running tasks e.g. text loading before images on a web page.
Drawbacks of concurrent processing
- Concurrent processing can take longer to complete when large numbers of users or tasks are involved as processes cannot be completed at once.
- There is an overhead in coordinating and switching between processes, which reduces program throughput.
- Just as with parallel processing, not all tasks are suited to being broken up and performed concurrently.
- Tasks can suspend and wait on each other indefinitely (known as deadlock).
What is parallelism?
Parallelism means that an application splits its tasks into smaller subtasks which can be processed in parallel, e.g. over multiple CPU cores at the exact same time.
Benefits of parallel processing
- Parallel processors enable several tasks to be performed simultaneously by different processors. It can speed up processing when repetitive calculations need to be performed on large amounts of data.
- Graphics processors can quickly render a 3D object by working simultaneously on individual components of the graphic.
- A browser can display several web pages in separate windows and one processor may be carrying out a lengthy search or query while processing continues in other windows.
Drawbacks of parallel processing
- There is an overheard in coordinating the processors
- Some tasks may run faster with a single processor than with multiple processors
A flight simulator allows a user to take control of a simulated aeroplane. The user can fly the plane in an environment that can simulate different weather conditions and additional planes in the sky.
Explain what is meant by ‘concurrent processing’ and describe one example of how the simulator could make use of it. (4)
Concurrent Processing:
One process does not have to finish before the other starts (1)
Example:
Each plane can move independently (1)
All move at the same time (1)
All need to react to different events (1)
The weather (1)
Wind, rain, direction of air etc. (1)
Each element needs to be run simultaneously (1)
A programmer is developing an ordering system for a fast food restaurant. When a member of staff inputs an order, it is added to a linked list for completion by the chefs.
The programmer is considering using concurrent programming.
Discuss how concurrent programming can be applied to the food ordering system and the benefits and limitations of doing so. (9)
AO1:
● Processes are happening at the same time / at overlapping times
● Only 1 process can actually happen at a time on a single core processor, concurrent tries to simulate multiple processes
● One process may need to start before a second has finished
● Individual processes are threads, each thread has a life line
AO2:
● Multiple orders can be made and added to the list at the same time
● Programming will need to allow multiple threads to manipulate a single list
● Will allow those reading and writing to manipulate at the same time
● Locking will need implementing – more complex programming
AO3:
● Will allow for multiple orders at the same time – as it would happen in real life
● Access to the linked list will need to be limited so it cannot be accessed / overwritten by two threads trying to do different operations
● Not all of the process will be paralleliseable. X processors does not mean it will run in 1/xth of the time of one processor.