Mail Archives: djgpp/2000/09/12/11:34:41
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 -