logo back up home forward   further reading more topics »

Parallel Programming

Before about 2005 most CPUs contained one core. This meant that the programmer could explicitly control the order that everything happened. This is illustrated in the following pseudocode:

// main loop
do {
  for every character step forward one time interval;
  for every combination of game objects check for collision;
  if collision has occurred take appropriate action; 
  render frame;
} until game ended;

However, if we want to use the power of multi-cores, we need to give each core different tasks to do but how to we divide this work up?

Most languages provide a way to do this, many allow the programmer to insert an instruction to start a new thread, when the program reaches this instruction the new thread will start executing instructions from some specified point in the program. This may, or may not, be executed in a separate core. When this thread has been started the original thread will continue with the code, so two threads are now running. Either of these threads can start further threads, and so on, so we can have a virtually unlimited number of threads.

How do we split up our game into different threads? For instance, should we start each game character running in a separate thread?

Writing parallel code in this way has lots of problems both for design and debuging.

Some of the problems of parallel code are:

 

 

New programming languages:

X10 - Prevents deadlock bug by classifying tasks in a hierarchy of "parents" or "children". It contains a command called "finish" that allows parents to wait for cildren, but not vice versa.

TM - Transactional Memory - The systems work out which tasks require the same piece of memory and lock those peices of memory at only the times required by each task.

 

 

 

 

 


metadata block
see also:

 

Correspondence about this page

Book Shop - Further reading.

Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them.

cover Executable UML - Covers compiler issues but no code
cover Executable UML - concentrates on patterns

cover Fast Track UML 2.0 - useful for people who know some UML but are upgrading to 2.0

Commercial Software Shop

Where I can, I have put links to Amazon for commercial software, not directly related to this site, but related to the subject being discussed, click on the appropriate country flag to get more details of the software or to buy it from them.

cover JBuilder - There is also a free version of Jbuilder at borland website . However its licence conditions are quite restrictive so you may prefer another java IDE.

Can this page be improved?

Please send me any improvements to here. I would appreciate ideas to make the pages more useful including error correction, ideas for new pages, improvements to wording. It helps if you quote the full URL of the page.

 

progam

I am working on a project which uses these principles, if you would like to help me with this you are welcome to join in, here:

for 3D programming: http://sourceforge.net/projects/mjbworld/

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2008 Martin John Baker - All rights reserved - privacy policy.