Re: Threads - When?
Lourens Veen wrote:
James Kanze wrote:
Le Chaud Lapin wrote:
Jeffrey
Richter writes:
"No programmer in his right mind wants to think about thread
synchronization as he is coding his app. This is because thread
synchronization has little to do with making the program do what
its true intention is."
At which point, I stopped reading, because the author obviously
doesn't know much about threading and thread safety.
I think we agree that threading is hard, and threading issues
(who is responsible for what, etc.) must be addressed at the
design level.
Personally, if there was a way to do it, I'd much rather not think
about thread synchronisation while I'm coding my app. I'd much rather
say "X needs to be done" and let the compiler figure out how to
divide that task across the (potentially dozens or hundreds of)
available cores.
I'm familiar with Fortran compilers which do this. It's more
difficult with C/C++ because of aliasing. One of the major
motivations for adding the restrict keyword to C was to allow
it.
But that's only one use of threading. (One that isn't well
supported by the existing Posix functions, as it happens.) In
my current work, I don't have any large loops or arrays which
would be susceptible to this sort of optimization. On the other
hand, I have a couple of hundred client connections; processing
a client request generally involves a number of blocking
operations, and I need to be able to advance other client
requests while waiting. In an earlier application, a GUI, I
needed to be able to redraw the screen while waiting for the
server to respond. In these cases, it's possible to write the
application without threads, by maintaining a lot of explicit
state, but it's much easier to use threads, and keep the state
implicitly in local variables, on the stack.
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]