ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/09/12/11:34:41

Date: Tue, 12 Sep 2000 20:40:23 +0600 (LKT)
From: Kalum Somaratna aka Grendel <kalum AT lintux DOT cx>
X-Sender: kalum AT goatbeard DOT grendel DOT net
To: Edmund Horner <edmund1 AT geocities DOT com>
cc: Edmund Horner <ejrh AT paradise DOT net DOT nz>, djgpp AT delorie DOT com
Subject: RE: Threading Advice
In-Reply-To: <000001c01c63$f8979e80$799e60cb@morgoth>
Message-ID: <Pine.LNX.4.21.0009122009360.1639-100000@goatbeard.grendel.net>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Tue, 12 Sep 2000, Edmund Horner spoke the following immortal words,

> Thanks for your advice, it sounds wise and is very encouraging.

Thanks, The thing is threading is not needed to give the user the illusion
of everything hapenning at the same time, for example a simple game like
Pacman never used threads, yet I am sure as everyone who has played with
it would agree, that there is the illusion of everything hapenning at
once.

It's just like the movies, there are only 26 frames per second and yet the
viewer sees everything as being continous action and the interuptions
between the frames are not visible.
 
> BTW, what exactly are race conditions and mutexes, and would I really
> encounter them if I used threads in a (relatively) simple program like this?

Well assume you have one thread handling the drawing to the screen, and
there is another thread that is handling the updating of the objects,
obviously you would want the drawing routine to start after all the
objects have been updated, otherwise if it starts say while only half the
objects have been updated, the resulting drawed screen would not show the
correct situation. 

What I mean to say is that say a grenade explodes near grendel and edmund,
now there are two objects (grendel and edmund) to be updated, normally
what will happen is that the updated routine will mark grendel as dead,
and mark edmund as dead, and since the drawing routine is called
afterthis, the drawing routine will correctly draw a correct picture of
grendel and edmund both dead.

But what would happen if the *drawing* routine was not controled, lets say
that the updating routine has only just finished marking grendel as dead,
and before it could mark edmund as dead, the drawing routine was called,
then as you may see the resulting screen would show the wrong picture of
grendel being dead while edmund is alive, just because the drawing routine
was not coordinated.

So this implies that you need some sort of synchronisation, and that would
involve using mutexes.

Actually if you want to check up on threads and write a few programs,
there is a very good tutorial called,
"Getting Started With POSIX Threads by Tom Wagner"
Also there are many tutorials available on programing posix threads, so
please check them out, the bst way is to run a search on google.com with
posix+tutorial as a search query.

BTW if you can't locate the above tutorial, just drop me a mail off the
list , and I'll post it to you.

Best Wishes,
Grendel

--
.---------------------.---------------------.----{)--.
| /"__ ._ _  _  _| _ |`-.grendel AT lintux DOT cx.-'(]__/|| |
| \__/ | (-'| |(_|(-'l_ `-===============-' [_]  .-: |
`--------------------------------------------/|\/| |-'






- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019