Multithreading - my piece of code
Reference:
http://www.codeproject.com/Articles/438/Introduction-to-Multi-threaded-Code
Simple code to use CriticalSection / Mutex…
http://rikeshkisnah.com/sw/mfc/mythreads/
Reference:
http://www.codeproject.com/Articles/438/Introduction-to-Multi-threaded-Code
Simple code to use CriticalSection / Mutex…
http://rikeshkisnah.com/sw/mfc/mythreads/
Couple of techniques -
TODO <Write my own DLL to use this concept and post here>
There are couple of things I am sure of
She was a gift from heaven
Born on the six eleven
She is Papa’s little girl
Every night, as I drop to my knees
To blow her goodnight kisses
I wonder with all what I have done wrong
I must have done something right
To deserve those hugs every night
Every day she grows, she is looking more like Estelle
Belle comme Estelle
Maybe more, with those ribbons and curls
She hops, she runs, she swirls
She demands the unconditional attention
from both Papa and Mama
Every time, I go away from home,
She cries Papa don’t go away today
Every minute apart from her
I have to concur
A piece of my heart is gnawed away.
I look forward to open the door
And see my angel runs on the floor
Towards me and shouting: Papa is back.
And Papa will always back for her
When she cries, papa will be with her
When she falls, papa will catch her
When she flies, papa will blow for her
As the north star, papa will always be there
Constant, Everlasting caring for rekha
a) For converting binary-to-decimal:
Start with a count of 0.
Work your way from the MSB to the LSB.
Rule:
Double your count.
If the bit is 0, do nothing.
If the bit is 1, add one to your count.
Repeat until there are no more bits.
For example, given a binary number, e.g., 11001100:
bit - count=0
1 - 2*0+1=1
1 - 2*1+1=3
0 - 2*3=6
0 - 2*6=12
1 - 2*12+1=25
1 - 2*25+1=51
0 - 2*51=102
0 - 2*102=204
Therefore 11001100=204
B) To convert from decimal to binary:
Given 204
204 is divisible by 2, write 0 (LSB)
204/2=102 is divisible by 2, write 0
102/2=51 is not divisible by 2, write 1
(51-1)/2=25 is not divisible by 2, write 1
(25-1)/2=12 is divisible by 2, write 0
12/2=6 is divisible by 2, write 0
6/2=3 is not divisible by 2, write 1
(3-1)/2=1 is not divisible by 2, write 1 (MSB)
Ref: http://www.zophar.net/forums/showthread.php?t=14509
http://www.zenoli.net/2007/03/quickly-convert-binary-to-decimal-in-your-head/
At my work, we use callbacks a lot. It took me a while to get the gist of it. Here are a list of good references to start with:
http://www.newty.de/fpt/callback.html
http://www.codeguru.com/cpp/cpp/cpp_mfc/callbacks/article.php/c10557
http://www.codeguru.com/Cpp/Cpp/cpp_mfc/callbacks/article.php/c4129/
I have written a program to try to grasp the meaning of the Function call backs:
http://rikeshkisnah.com/sw/MyCbTest/
Here are the guidelines that I have come up for my own design purposes
1) Whenever a class is written, to ensure that output is directed to a generic output i.e gui, console etc
Create
a) Function pointer to have the callback function (Do not forget to #define CALLBACK __stdcall)
More on http://www.hackcraft.net/cpp/MSCallingConventions/
b) Create 2 pointers
-> Function pointer - which will contain the function callback
-> userData - which will contain the caller object
c) Instatiation InstallCallBack function and DeInstallCallBack function for the caller
d) Provide a default CallBack function in case the caller does not InstallCallBack
Tricky or catch : Callback functions must be static and must have __stdcall for Windows
2. On the caller side
a) Create an instatiation of the class
b) Write a static function which will follow the function pointer signature
c) In the static function, provide the userData (which is the object) and the data to be passed in
Wikipedia article I contributed the code:
http://en.wikipedia.org/wiki/Strategy_pattern
Excellent tutorial
I was confused on the terminology of Isolation, VSWR during the course of my work. I came across this good tutorial from NI. I am pasting it for reference.
I bought this phone:
https://www.singtelshop.com/mobile/index.jsf#/mobile/catalogue/phones/MOTOROLA/ATRIX
I was able to root this phone after some googling and some tweaks here and there.
[Caution] The following link does not root on the phone model above:
http://www.androidauthority.com/how-to-root-the-motorola-atrix-11523/
If you are worried about bricking your phone i.e your phone will not power up, rest assure that the event it happens is very unlikely, as from my experience - to kill your phone - you will have to mess up the bootloader badly. The bootloaders on Moto phones now are signed and they are baselined quite a few months before the phones are shipped out. So unless you have a very old bootloader, you should be safe.
Next question, you might wonder why you would like to root your phone, here is a good reason:
http://www.addictivetips.com/mobile/top-10-reasons-to-root-your-android-phone-2/
And if you are still on the fence, here is another article on not wanting to root your phone:
http://janetalkstech.com/2011/why-i-havent-rooted-my-motorola-atrix
Ok here are the procedures:
URL for reference: http://briefmobile.com/motorola-atrix-4g-root
[Works on Windows XP, I have not tried Windows 7]
Step 0: Make sure you have installed all the motorola drivers and motorola Media Link installed
http://www.motorola.com/Support/US-EN/Consumer-Support/Software/Motorola-Media-Link
And ensure your atrix works with them once you connected i.e you are able to use the software
Step 1: Download http://rikeshkisnah.com/sw/atrix/root.rar
at c:\root [it is advisable to put it in your c:\ drive as I have read some forums there are issues if you place it on other drives - though I do not see any reason it should not work - but it is better to be safe than sorry…]
Step 2: Place the device in FastBoot mode
Power down the phone. And power it up by holding the volume down button. It will power up with the FastBoot screen.
Step 3:
Using windows command prompt, go to c:\root and issue the following commands
What in effect you are doing, you are flashing a rom flash to with the super user application and rebooting for it to be initialized for startup
Step 4: Activate USB debugging and launch the shell
Power up the phone and activate USB debugging [Settings -> Applications -> USB debugging]
Go to c:\root in the command prompt
-> adb shell
[this will launch a bash shell]
In the bash shell type
/preinstall/su
[get the super user access]
/bin/mount /system -o remount,rw
[mount the filesystem]
cp /preinstall/su /system/bin/su
[copy the hacked su app to the system]
chmod 6755 /system/bin/su
[give the app rwx access]
PATH=/system/bin:$PATH pm install /preinstall/Superuser.apk
[install the application icon]
After this reboot your phone and voila. I am in a process of writing an application to simplify the process.
We take a look back at the rousing speech delivered by the former CEO of Apple, to Stanford’s graduating batch of students in 2005.

On June 12, 2005, then-CEO of Apple Computer and Pixar Animation studios, Steve Jobs, delivered a rousing speech to the graduating batch of students from Stanford University.
In his speech, he shared his personal story of how he got into, and eventually dropped out of, college. He also shared how at 30, he got fired from Apple, the company that he started.
But to him, it was the best thing that ever happened.
As Jobs made his announcement of his resignation at Apple on August 24, we thought it appropriate to take a look back at his inspiring speech that has remained relevant through the years.
Below is the prepared text of his Commencement address, in full:
The first story is about connecting the dots.
I dropped out of Reed College after the first 6 months, but then stayed around as a drop-in for another 18 months or so before I really quit. So why did I drop out?
It started before I was born. My biological mother was a young, unwed college graduate student, and she decided to put me up for adoption. She felt very strongly that I should be adopted by college graduates, so everything was all set for me to be adopted at birth by a lawyer and his wife. Except that when I popped out they decided at the last minute that they really wanted a girl.
So my parents, who were on a waiting list, got a call in the middle of the night asking: “We have an unexpected baby boy; do you want him?” They said: “Of course.” My biological mother later found out that my mother had never graduated from college and that my father had never graduated from high school. She refused to sign the final adoption papers. She only relented a few months later when my parents promised that I would someday go to college.
And 17 years later I did go to college. But I naively chose a college that was almost as expensive as Stanford, and all of my working-class parents’ savings were being spent on my college tuition. After six months, I couldn’t see the value in it. I had no idea what I wanted to do with my life and no idea how college was going to help me figure it out. And here I was spending all of the money my parents had saved their entire life. So I decided to drop out and trust that it would all work out OK. It was pretty scary at the time, but looking back it was one of the best decisions I ever made. The minute I dropped out I could stop taking the required classes that didn’t interest me, and begin dropping in on the ones that looked interesting.
It wasn’t all romantic. I didn’t have a dorm room, so I slept on the floor in friends’ rooms, I returned coke bottles for the 5¢ deposits to buy food with, and I would walk the 7 miles across town every Sunday night to get one good meal a week at the Hare Krishna temple. I loved it. And much of what I stumbled into by following my curiosity and intuition turned out to be priceless later on. Let me give you one example:
Reed College at that time offered perhaps the best calligraphy instruction in the country. Throughout the campus every poster, every label on every drawer, was beautifully hand calligraphed. Because I had dropped out and didn’t have to take the normal classes, I decided to take a calligraphy class to learn how to do this. I learned about serif and san serif typefaces, about varying the amount of space between different letter combinations, about what makes great typography great. It was beautiful, historical, artistically subtle in a way that science can’t capture, and I found it fascinating.
None of this had even a hope of any practical application in my life. But ten years later, when we were designing the first Macintosh computer, it all came back to me. And we designed it all into the Mac. It was the first computer with beautiful typography. If I had never dropped in on that single course in college, the Mac would have never had multiple typefaces or proportionally spaced fonts. And since Windows just copied the Mac, it’s likely that no personal computer would have them. If I had never dropped out, I would have never dropped in on this calligraphy class, and personal computers might not have the wonderful typography that they do. Of course it was impossible to connect the dots looking forward when I was in college. But it was very, very clear looking backwards ten years later.
Again, you can’t connect the dots looking forward; you can only connect them looking backwards. So you have to trust that the dots will somehow connect in your future. You have to trust in something — your gut, destiny, life, karma, whatever. This approach has never let me down, and it has made all the difference in my life.
My second story is about love and loss.
I was lucky — I found what I loved to do early in life. Woz and I started Apple in my parents garage when I was 20. We worked hard, and in 10 years Apple had grown from just the two of us in a garage into a $2 billion company with over 4000 employees. We had just released our finest creation — the Macintosh — a year earlier, and I had just turned 30. And then I got fired. How can you get fired from a company you started? Well, as Apple grew we hired someone who I thought was very talented to run the company with me, and for the first year or so things went well. But then our visions of the future began to diverge and eventually we had a falling out. When we did, our Board of Directors sided with him. So at 30 I was out. And very publicly out. What had been the focus of my entire adult life was gone, and it was devastating.
I really didn’t know what to do for a few months. I felt that I had let the previous generation of entrepreneurs down - that I had dropped the baton as it was being passed to me. I met with David Packard and Bob Noyce and tried to apologize for screwing up so badly. I was a very public failure, and I even thought about running away from the valley. But something slowly began to dawn on me — I still loved what I did. The turn of events at Apple had not changed that one bit. I had been rejected, but I was still in love. And so I decided to start over.
I didn’t see it then, but it turned out that getting fired from Apple was the best thing that could have ever happened to me. The heaviness of being successful was replaced by the lightness of being a beginner again, less sure about everything. It freed me to enter one of the most creative periods of my life.
During the next five years, I started a company named NeXT, another company named Pixar, and fell in love with an amazing woman who would become my wife. Pixar went on to create the worlds first computer animated feature film,Toy Story, and is now the most successful animation studio in the world. In a remarkable turn of events, Apple bought NeXT, I returned to Apple, and the technology we developed at NeXT is at the heart of Apple’s current renaissance. And Laurene and I have a wonderful family together.
I’m pretty sure none of this would have happened if I hadn’t been fired from Apple. It was awful tasting medicine, but I guess the patient needed it. Sometimes life hits you in the head with a brick. Don’t lose faith. I’m convinced that the only thing that kept me going was that I loved what I did. You’ve got to find what you love. And that is as true for your work as it is for your lovers. Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven’t found it yet, keep looking. Don’t settle. As with all matters of the heart, you’ll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don’t settle.
My third story is about death.
When I was 17, I read a quote that went something like: “If you live each day as if it was your last, someday you’ll most certainly be right.” It made an impression on me, and since then, for the past 33 years, I have looked in the mirror every morning and asked myself: “If today were the last day of my life, would I want to do what I am about to do today?” And whenever the answer has been “No” for too many days in a row, I know I need to change something.
Remembering that I’ll be dead soon is the most important tool I’ve ever encountered to help me make the big choices in life. Because almost everything — all external expectations, all pride, all fear of embarrassment or failure - these things just fall away in the face of death, leaving only what is truly important. Remembering that you are going to die is the best way I know to avoid the trap of thinking you have something to lose. You are already naked. There is no reason not to follow your heart.
About a year ago I was diagnosed with cancer. I had a scan at 7:30 in the morning, and it clearly showed a tumor on my pancreas. I didn’t even know what a pancreas was. The doctors told me this was almost certainly a type of cancer that is incurable, and that I should expect to live no longer than three to six months. My doctor advised me to go home and get my affairs in order, which is doctor’s code for prepare to die. It means to try to tell your kids everything you thought you’d have the next 10 years to tell them in just a few months. It means to make sure everything is buttoned up so that it will be as easy as possible for your family. It means to say your goodbyes.
I lived with that diagnosis all day. Later that evening I had a biopsy, where they stuck an endoscope down my throat, through my stomach and into my intestines, put a needle into my pancreas and got a few cells from the tumor. I was sedated, but my wife, who was there, told me that when they viewed the cells under a microscope the doctors started crying because it turned out to be a very rare form of pancreatic cancer that is curable with surgery. I had the surgery and I’m fine now.
This was the closest I’ve been to facing death, and I hope it’s the closest I get for a few more decades. Having lived through it, I can now say this to you with a bit more certainty than when death was a useful but purely intellectual concept:
No one wants to die. Even people who want to go to heaven don’t want to die to get there. And yet death is the destination we all share. No one has ever escaped it. And that is as it should be, because Death is very likely the single best invention of Life. It is Life’s change agent. It clears out the old to make way for the new. Right now the new is you, but someday not too long from now, you will gradually become the old and be cleared away. Sorry to be so dramatic, but it is quite true.
Your time is limited, so don’t waste it living someone else’s life. Don’t be trapped by dogma — which is living with the results of other people’s thinking. Don’t let the noise of others’ opinions drown out your own inner voice. And most important, have the courage to follow your heart and intuition. They somehow already know what you truly want to become. Everything else is secondary.
When I was young, there was an amazing publication called The Whole Earth Catalog, which was one of the bibles of my generation. It was created by a fellow named Stewart Brand not far from here in Menlo Park, and he brought it to life with his poetic touch. This was in the late 1960’s, before personal computers and desktop publishing, so it was all made with typewriters, scissors, and polaroid cameras. It was sort of like Google in paperback form, 35 years before Google came along: it was idealistic, and overflowing with neat tools and great notions.
Stewart and his team put out several issues of The Whole Earth Catalog, and then when it had run its course, they put out a final issue. It was the mid-1970s, and I was your age. On the back cover of their final issue was a photograph of an early morning country road, the kind you might find yourself hitchhiking on if you were so adventurous. Beneath it were the words: “Stay Hungry. Stay Foolish.” It was their farewell message as they signed off. Stay Hungry. Stay Foolish. And I have always wished that for myself. And now, as you graduate to begin anew, I wish that for you.
Stay Hungry. Stay Foolish.
Thank you all very much