Brad Williams said:
You can call it names, but if and when it gets the job done, it's a good
thing.
That sounds like the recipe for bad code - and unsafe code (from a
thread safety point of view). There are any number of bits of code
which may happen to work on your development machine, but which are
very *far* from good things - because they may well *not* work on
machines with more processors, or a different default encoding, or any
number of other things.
The classic gotcha with ad hoc message pumping is you have to watch
out for re-entrency -- eg, if you create a message pump within a button
event, first disable the button so you don't get the same event again while
you're processing the first one. Of course that may be something you want
to control for when spawning threads, too, so it's not a unique problem to
DoEvents().
Well, there's more to re-entrancy than that though, isn't there? The
link I posted before gives some idea of the kind of nastiness you can
run into.
Once there's more than one thread touching your data, the complexity at
run-time increases immensely.
Absolutely. I'm certainly not pretending that multi-threading is
simple. I just find it easier to work with than the spectre of re-
entrancy. As Chris Brumme says in his log:
<quote>
Avalon also has made a conscious design choice to favor deadlocks over
reentrancy. In my opinion, this is an excellent goal. Deadlocks are
easily debugged. Reentrancy is almost impossible to debug. Instead,
it results in odd inconsistencies that manifest over time.
</quote>
While I wouldn't say that deadlocks are *easily* debugged, I'd say
they're not *too* bad - and they're *relatively* easy to avoid, if
you're careful about documenting what locks happen when.
It can be hard to impossible to test (in unit
tests or later) for all the potential bugs in multithreaded code (on our
dual procs, right?) -- and oftentimes it will "work" in a few test runs and
so you think you've got it licked, but you don't.
Yup - and the same is true for DoEvents, isn't it?
And if you are lucky enough to realize there's a problem, debugging
is very tricky. ... Okay, I shouldn't say "you" because I'm speaking
from experience and I'm the one whose had all these headaches in the
past, but I don't think others are immune.
Absolutely not - and threading really *is* a nightmare. DoEvents is
also a nightmare - it's just one which sort of *pretends* to be simple.
It has a different set of problems to work around.
Now, as I've said before, sooner or later you will *need* to use
threads (do anything which might block in DoEvents and you've got an
unresponsive UI), why not become really proficient in one area rather
than knowing a little about two different areas?