CM10228 / Programming Ib:   Lab 2

Concurrency and Networking: Threading (Concurrency)

<< Back to contents

Background:

In the early days of computing when programs were written on punch cards, you had to book a time slot on the computer in order to get to run your program. Errors, having to wait for input, or even just someone booking too much time were hugely inefficient uses of computing power when there were other programs that needed to be run. Nowadays, operating systems are ubiquitous, and it is possible to run multiple programs at the same time with no obvious switching, as far as the user is concerned. This area of computer science is called concurrency. A thread is like a 'worker' that runs some instructions. Using multiple threads allows the processor to allocate time to different programs and switch between them seamlessly. Furthermore, if one program is busy waiting for something that the processor can't help (e.g. user input), then it can spend time on the others instead. But that's not all, a single program will often have multiple threads. The primary purpose of this is so that it can handle multiple jobs 'at the same time'. For instance, a game might have one thread running the GUI, another running the AI, and another communicating over the network. Since multi-processor and multi-core systems came along, threads are also useful for separating a single large task to be handled more efficiently by separate processors (or cores).

Do this:

Now you have learned the basics of threads. This is all you need for this sheet, however there are a few more topics that are worth learning and will help you with coursework 2, in particular:

Do this: (in your own time)

But for this lab it is time to move on to networking.

Networking >>



page author: Andrew Chinery
last updated: 01 March 2013