after reading a few documents about multithreading.
it seems that multithreading isn't as difficult as i previously though, and maybe not as difficult as toady thought.
in the following examples(referring to something i did not write myself, and which is in fact one of the few examples i understand!)
the major problems are from order of execution. part of a thread runs in the middle of another thread(literally running between the lines of another part of the program)
in the example they wrote-
there is one instance variable with a default value of 0, and 20 created threads sharing it.
the following threads 0-19 loop around, adding 10, then subtracting 10 a thousand times.
within a single block of code
simultaneously, or rather, between the functional lines of the other programs, the threads write the value of the instance variable.
the program printed these results:
booThread0 sees the number: 0
booThread1 sees the number: 0
booThread2 sees the number: 0
booThread3 sees the number: 0
booThread4 sees the number: 10
booThread6 sees the number: 10
booThread7 sees the number: 10
booThread8 sees the number: 10
booThread9 sees the number: 10
booThread10 sees the number: 0
booThread11 sees the number: 0
booThread12 sees the number: 0
booThread13 sees the number: 0
booThread5 sees the number: 0
booThread14 sees the number: 0
booThread15 sees the number: 0
booThread16 sees the number: 0
booThread17 sees the number: 0
booThread18 sees the number: 0
booThread19 sees the number: 0
booThread0 sees the number: 0
booThread1 sees the number: 0
booThread3 sees the number: 0
booThread4 sees the number: 0
booThread6 sees the number: 0
booThread8 sees the number: 0
booThread9 sees the number: 0
booThread2 sees the number: 0
booThread7 sees the number: 0
booThread10 sees the number: 10
booThread11 sees the number: 0
booThread12 sees the number: -10
booThread13 sees the number: -10
booThread5 sees the number: -10
booThread14 sees the number: -10
booThread16 sees the number: -10
booThread17 sees the number: -10
booThread18 sees the number: -10
booThread19 sees the number: -10
of course, this is in java, and multithreading in C or C++ is probably more difficult.>
also
just to keep it straight, i don't know multithreading, this example just spoke to me very logically, from the site
http://docs.rinet.ru/JWP/ch16.htm----
new entry:
since we don't know toady's formula, we can only make vague passes as to how it works
there is one problem that i cannot beat easily in the following example:
when dwarves collide.
yet.
dwarf fortress one tile tall and wide: most everything but pathfinding breaks!
assume a single array, containing the passable/impassable value for all tiles
for a dwarf to determine if he can get from point a to point b, he must check all tiles inbetween.
for two dwarves to determine if they can get from point a to point b, they must both check all tiles inbetween, which may overlap.
what happens if two threads of a multiprocessor try to access the same data at the same time?
does it even happen??
jeeze i think i'll need to come back to this when i know C.
check back this weekend as i ponder and do research
also, bear in mind that my theories are only for me to learn, not that i think toady should really implement multithreading...