Through recent frustrations, and needless to say, core dumps, I have realized that C++ as a language have some distinct features often associated with men: It can only do one thing at a time, and it cannot communicate. In this post I'll elaborate on these.
It Can Only Do One Thing at a Time
In C++ threads or the notion of multiprocessing simply does not exist. The language has neither a thread concept nor any thread synchronization primitives like mutexes, semaphores and locks.
Even relatively simple constructs like static members simply do not work in a multi-threaded context. As described by Scott Meyers and Andrei Alexandrescu in C++ and the Perils of Double-Checked Locking, no matter how many volatile keywords or extra locking you add in the mix, it still won't work consistently. Some compilers try to help you by fixing this for you, but since that is compiler implementation dependent it does more harm than help.
C++ has no thread-safe memory model, and does not provide any means for a memory barrier. Which means that any "clever" compiler or instruction dispatcher is free to reorder your statements in whichever way provides the same result in a single thread of execution.
C++ Cannot Communicate
What is the de facto standard for communicating with the outside world, and has been for the last two decades? The Internet Protocol, or more specifically, the TCP and UDP protocols on top of it. But the C++ language does not support this protocol. The only means of communication provided by the language are streams for input and output, and they can only be used for talking to files or to the console.
You Can Teach C++ New Tricks
In the recent years I've learned the art of walking and chewing gum at the same time. I can even pay attention to a conversation while doing other stuff, or at least I think I can.
Being a married man I have also learned to cope with my lack of communication skills, to some extent. Neither of these feats came easy. They were achieved after failing a lot and suffering many crashes.
I have never tried teaching a man to do these things, but having been taught these capabilities has provided some insight into the requisite effort and amount of frustration involved.
Trying to teach C++ to do several things at the same time while communicating with others can also be accomplished. It is however probably equally frustrating as teaching your significant other something he obviously wasn't designed to do. Both capabilities require that you deal with the more primitive foundation the individual has evolved from (Neanderthals and C), and relying on cultural constructs (operating system interfaces) that have been added on top of evolution and behave differently from individual to individual.
In many circumstances the resulting behavior is undefined, and will certainly cause some surprises. You also have to meticulously and in great detail instruct your friend on every step required to perform the task, in a language he understands.
The Modern Man: C++0x
Men have evolved, and so has C++ as well. In C++0x the language has grown the capability of doing several things at once, but it still prefers to do so alone in a dark corner.
0 kommentarer:
Legg inn en kommentar