The Monkey and the Oiled Bamboo Pole
Children in India are quite good at math. And one of the math problems is that of a monkey climbing an oiled bamboo pole.
It goes like this - a monkey is trying to reach the top of an oiled bamboo pole. When he climbs up 3 feet, he slips down 2 ft. Climbing up 3 ft takes 3 seconds. Slipping down 2 ft takes 1 second. If the pole is 12 ft tall, how much time does the monkey need to reach the top?
I leave the solution as a trivial exercise for the little grey cells.
However, let me get to the point now. The question is - in the first place, why should a monkey climb an oiled bamboo pole? Does he not have other poles to climb that pose less challenges?
Jokes aside, we often see the need to address root cause of problems in software, before even attempting to solve them. Sometimes, the problem can be made to disappear altogether.
A real life example - in one program, I had to read a certain value from a hardware key. But, the driver dlls were taking too much time to load. So, I could not read the value directly.
The executable in question was part of a clutch of exes. And, one of the other exes already read the value, even before the target exe started up. So, a possible solution was to read the already existing value.
Fine; I started thinking of interprocess communication (IPC). My line of thinking was something like this: “I need to transfer the value without windows messaging because there is no message pump at the point we want to read the value … so a shared memory or socket based IPC approach would be nice.”. A value transfer problem morphed into an IPC problem, and all I was thinking about was how to design an elegant IPC mechanism.
Then, I realised that the target exe was a child process of the exe that already had the value - and, since child processes inherit environment variables of their parent, I could use an environment variable to pass this information. Two lines of code did the job - one line in the parent exe to set the variable; another line in the child exe to get the variable.
So much for IPC.
Sometimes we need to ask if the monkey really needs to climb the oiled bamboo pole.



hmmm….nice solution mainly simple code solve tough task also easy for all to understand..monkey jumped from the top of the nearest bamboo to the oiled bamboo..:)