Wednesday, July 30, 2008

'Benign' Addiction

I am in Kolkata now for a long vacation, for around two months.

I was naturally looking forward to be with my Mother who was to undergo a complete knee replacement surgery, and naturally if the home maker is on complete rest there should be someone to take care of house hold errands.

All is going as planned at home, I am spending most of the time at home, with my parents, helping whenever needed. I also get time to myself - I am indulging in my hobbies - painting, dancing, practicing yoga. In spite of everything there is always something on my mind which disturbs me. I only realized what it was while I was reading an editorial in Times of India - "A Wordy Addiction". That feeling of emptiness is attributed to my addiction to freedom and fondness for the forbidden.

I was brought up amidst a lot of restrictions, where there were colliding opinions for the simplest of things. It was purely because of difference in the thought process between generations. But when I moved out of home for work, I was all by my own and I freely indulged in a gamut of activities. In no time even without my realizing I got so used to this life style which was world apart from that in which I was brought up, that I am finding it quite difficult at home.

I don't know whether this is justified, but I feel sad and I fail to understand how that is possible - I am so fascinated to a life which I am leading just for a couple of years which is versus twenty four years of my life.

Friday, March 28, 2008

Passing thought..


It was the umpteenth time when I was taken aback by the pathetic plight of the "poor" while I was held up in a traffic jam. My mind froze upon some thoughts while I saw a couple of ill-clad children rush towards the traffic as the cars decelerated at the signal. Each of them knew exactly what to do - They are experts at putting on expressions and each of their voices was also toned well enough to drive "mercy" out of anyone. I was in an auto rickshaw as a part of that traffic jam and I could clearly make out what their "tears" were made up of. It was really shocking! I wish their parents had channelized this much of thinking into something more constructive. I wondered how these people can harness sympathy out of the passers-by but then it is rightly so I guess. It is a real pity that these children are forced into an act which I feel is worse than crime.

The traffic moved on and I was left with nothing but helplessness and remorse. I guess there are many who feel likewise but it needs immense determination and hard work to eradicate such unhealthy components from our neighborhoods which many (including me of course) don't indulge in. It is because we are too selfishly involved in our daily chores and so we think we do not have the time for these.

P.S I am not being judgmental about which course we adopt, its just a thought. But at the end of it I am genuinely happy to know there are dedicated organizations which claim to work towards improvement of the social conditions and I hope they are successful even if by a small percentage.

Monday, March 24, 2008

How 'volatile' are they?

What are volatile variables?

A variable in Java if declared volatile ensures the visibilty of the variable when shared across different threads. Lets consider a variable, say an int i and this variable is declared volatile. Now if Thread 1 changes the value of i from1 to 10 at time t = 0. At time t=1 the value of i which thread 2 reads is 10 and not 1. This is bacause for volatile variables the values which is read is the shared value, which is the most recent value of the variable.

Are they as powerful as locks?

So if the visibility of a shared variable is guaranteed, can one do away with locking with volatile variables?

Consider the following:

A Runnable Class:

public class VolatileRunnable implements Runnable{

private volatile int i;// This is a shared variable

public void run() {

for (int j = 0; j < 10000; j++) {
i++;
}
}

public int getI() {
return i;
}
}



And a main method which uses the Runnable:

public static void main(String[] args) throws InterruptedException {
VolatileRunnable r = new VolatileRunnable();
Thread t1 = new Thread(r);
Thread t2 = new Thread(r);

t1.start();
t2.start();
t1.join();
t2.join();

System.out.println("r.getI() = " + r.getI());
}


Now since the variable i is shared and declared volatile what would be the expected output? To me, going by the definition of volatile the output would be (number of threads) * 10000 (20000 in this case). On running the program I saw the output of 20000 was not always true. There were times when the output was 19445, 19667 etc.

Why is that even if the variable is declared volatile?

The operation i++ is actually a series of read, use and write operations on the variable i. Each of these individual operations are atomic but the combination of them is not.

A snapshot of time

t1 Thread 1 read (i = 3)
t2 Thread 2 read (i = 3)
t3 Thread 1 used (i + 1 = 4)
t4 Thread 2 used (i + 1 = 4)
t5 Thread 1 wrote (i = 4)
t6 Thread 2 wrote (i = 4)


This is a case of lost update. This is what would have happened when the above example was run. Some of the increments were lost and hence the non deterministic output.

Hence in this case even though the variable was volatile atomicity was not guaranteed and so synchronization is indispensable to ensure the expected outcome.

The moral:

Volatile variables are not enough when the expected behaviour in any piece of code depends on the value of a variable before any write operation.

Wednesday, January 30, 2008

Mind fresheners

Some songs carry a feeling of unknown acquaintance quite difficult to express.
They take me back in time and I enjoy the feeling though it has an element of nostalgia. I can say a sweet blend of good memories and sad ones but if I really try to identify the times it would be all in vain.

It is not for the first time these thoughts have occurred to me but I feel like penning them down today while I am listening to Ustad Rashid Khan's Aoge Jab Tum.
Yet another song which I love listening to, it encompasses a very fresh flavour with it is Jab Tassavur Mera by Ghulam Ali.
I find its extremely difficult to identify whether it is the lyric or the music that entices me but my state thereafter is just heavenly!

Sunday, July 22, 2007

These are a few of my favorite things....

I only clicked on the link http://zenhabits.net/2007/07/75-simple-pleasures-to-brighten-your-day/ thinking I would just glimpse over but there were some parts of the article which went unnoticed. I was just about to close the window when I realized how well I could relate to some of the points enlisted there. These might not necessarily brighten my day but they do leave me exhilarated for some time at least, and even more as I write about these.

So whats on my list :
  • Walking barefoot in grass - I enjoy the ticklish feeling as I walk - my feet pressing into and off the soft grass is a lovely feeling.
  • The smell of fresh uncut grass - this goes extremely well with the smell of wet earth. It leaves me rejuvenated! The latter is generally after a rain. (How about getting drenched in rain.?!!)
  • Hugging a child tightly - and what follows for most of the times is a squeak or a whimper which makes me cuddle the kid even tighter!
  • A long conversation with a good friend - all the better if over a cup of elaichi or ginger tea or coffee - It can leave me relaxed and my mood uplifted especially if I have laughed throughout the conversation. Its the same as I talk to some one unknown.
  • Acting crazy in public - Believe me its crazy! Its not that I do it intentionally - I guess that's my build - :) I get into the fits generally when I am with a good friend - (He/She should not be put off by that - and if that's the case I am put off even more! ). I knew I like being like that only when I came upon this article.
  • Being gifted with flowers and adorning my home with flowers - Buying fresh flowers every Sunday morning, arranging it on your coffee table of your living room, your dining table and bed room - what a delightful thought!!
  • Loud music - when your own voice is inaudible and you are unable to think of anything even when you want to - It can be intoxicating!
  • Enid Blyton books -I remember my school days some how (my school days are the best days of my life) I plan to have a collection of Enid Blyton books!
  • Hearing someone who can make you laugh.
I don't know if this is an exhaustive list but surely a few of my favorite things!

Wednesday, July 18, 2007

On Movies.... this and that....

The movie buff in me from time to time is active after brief periods of hibernation. If I were to describe in one sentence the kind of movies I enjoy for most of the times I would say - "Any story which reflects the director's excellence". This perhaps speaks for why I enjoy a lot of art films or maybe commercial cinemas which are based on some real incident. I am not saying I am a judge of good movie direction neither do I claim that all art movies are directed well.

Of late I have been watching a lot of Bengali films - I have liked all the movies by Satyajit Ray and Rituporno Ghosh I have seen so far. This weekend I grabbed a few VCDs - Antareen(The confined), Sati (The Ritual) and Juganto(End of an Era). These are delicacies by Mrinal Sen and Aparna Sen. I watched Antareen. Its a simple story, there is nothing very elaborate about the sets, it has only ten characters in the film, there are a total of three different locations in the film and yet the film was not seeming slow paced, it kept me engrossed till the end. Most of the films by these directors are made such. Their unique selling point undoubtedly is their story line and the subtle, intricate moves in movie direction.

I have been born and brought up in Calcutta and when I was young I remember my Father going to watch a lot of Bengali films in the theatre. One of the movies he was once trying to convince my Mother, my sisters and myself into watching was Unishe April(19th April). I think the movie had just released then. Obviously none of us agreed - I think because we were lured into watching movies with extravagant sets, good music, known actors.

I am sure it is not easy and I don't know whether I would be really doing it, but I am truly inspired to shoot a short documentary film (may be ten minutes long). It would require immense expertise I feel. I will surely think over it at least. Or is that the maximum I will do?!

Friday, July 6, 2007

Talk over coffee with Sanjeev Kapoor...

It was just another day - Lazy morning, going to office even lazier, stand up meeting, coffee, coding, some meetings, lunch, more meetings - This went on till five in the evening. All of a sudden ' the friday evening' feeling started to percolate especially in the cubicle where I sit. My colleague and I start some gibberish conversation and we come to the topic of 'filter coffee'. By the way this colleague of mine claims he has evolved into Chef Sanjeev Kapoor by virtue of his attempts to cook. His name is Bharath - if I were to describe him in a few words I would say ' A guy who is really proud to hail from Chennai'. Basically a very simple guy who can enkindle any situation into a funny one - I think very few people can do that.

So we had a session on 'How to make filter coffee'. After a futile attempt at explaining me the making process, which lasted for say fifteen minutes, he made a couple of calls to his mother, we searched wikipedia, and finally zeroed upon the ingredients and the procedure. This was his plight after making filter coffee regularly! Atleast he says he is regular! At the end of it I learnt how to use the filter coffee maker which I had been misusing so long.

I was wanting to move out early from office today and that urge strengthened after I learned our 'boss' had left. It was easy convincing Bharath to accompany me for a plate of Rava Idli to a nearby coffee shop Miverva. We were ready to leave in no time. We truly lived up to the saying -' the mice are out when the cat is away' !

Bharath, I realised has turned into a glutton ever since he 'quit' smoking. (his definition of quit is to abstain till the next time he does it) and I dont need to quit anything for that :). We devoured the idlys at the speed of 1 idly in about 2 mins. We bahaved as if we had not eaten anything and ordered dosa next. A cup of coffee followed. I avidly enjoy the minerva coffee as it is 'filtered' by nature! We talked a lot over the coffee and so called evening snacks. It was really good fun.
Albeit there was nothing unusual about the evening I was feeling fresh and happy by the end of it.

Am back home now and I prepared coffee - the filtered way! Cheers Bharath dear!