You are on page 1of 2

Practical 5

Mr Andrew Cook
21 February 2022

Introduction
The focus of this practical is on basic concurrency operations and getting com-
fortable with the Threading module and specifically the Thread class within
it.

Task 1
Try the examples given in Lecture 5b.
What happens if you delete the Thread.join() commands?
Change how long each task waits - perhaps by subtracting the thread number
from a fixed value. Do the processes complete in different orders now?

Task 2
In lecture 5a we outlined a scenario where Concurrency might be useful by
describing the process of cooking a breakfast.

2.1: Sequential approach


Create a series of functions which will be performed sequentially:
Boiling Kettle - Takes 20 seconds from when it starts.
Cooking Toast - Takes 15 seconds from when it starts.
Boiling Water - Takes 15 seconds from when it starts.
Cooking Egg - Takes 10 seconds from when it starts.
How long does this program take to complete?

2.2: Concurrency
Using the Threading module and Thread object re-run the above program using
concurrency.
How long does this new program take to complete?

1
2.3: Object-Oriented approach
Extend the Thread class to produce a subclass for each of the three tasks in
making breakfast.

You might also like