Tuesday, July 26, 2005

Car-car dekho

Although I am not a gearhead, unlike other bloggers I know, this red-blooded male's heart does skip a beat at the sight of a fine piece of engineering.

So, while making my way to office on a Mundane Monday Morning, there was the sudden skipping of a beat in yours truly's heart when a Lotus Elise (exact same color as the photo in the link) stopped right next to me at a light. This was my first darshan of this beauty.

Just when I was getting back to normal, a 2005 Corvette (again the same color as in the photo ) passed by.

Living in the Redmond area, with a lot of Micro-serfs who made their millions when the Microsoft stock was shooting sky-high like Google means that everyone and his uncle here drives a BMW 3-series, and 5/7 series or Porsche Carreras are so common, that they are (almost) passé. But, a Lotus Elise or a Corvette? Now you're talking. Just as I was pulling into the street where my office stands, a lime-green 2005 Mustang passed by.

Needless to say, my day was made.

To top it all off, an Indigo Corvette (it was a hard-top, not a convertible like this photo)made its way onto a light right next to me on the drive back home.


Till then, how about this for consolation: The rush hour traffic today was so slow, that I tailed the Elise for almost 3 miles.On internal roads with 40 mi. speed limits of course.

Monday, July 25, 2005

The man behind the lens

A lovely insight into the mind of master craftsman Ram Gopal Verma. Favorite quote?

"I’ve time and again said that I don’t make films to make money. I need money to make films."

Friday, July 22, 2005

Potter, Potter everywhere

...and not a review shall I read.

Yes, sirree. Haven't read a single review of Harry Potter VI (HPATH-BP, if you so desire). I haven't bought it yet, but soon may. Thought I'd get some predictions, questions and expectations for the book out of the way this time around, before I read it. And no, no reviews shall be read till the book is consumed.

1. Do Ron and Hermione make any headway? It's obvious that the sparks are a'flying.
2. Harry Potter gets a new girlfriend? My guess. We need a new female interest. He is a teenager, and I'm sure he's outgrown Cho Chang.
3. Neville Longbottom grows to be a stronger and more interesting character .I hope so. His backstory in HPATGOF (No. V) was compelling. He needs some serious redemption now.
4. More background on Snape's role in the war on evil.
5. A new teacher for Defence Against the Dark Arts (correct me if I'm wrong here).I hope it is an interesting character.
6. More gloominess all around? My favorite of the series is No. III (HPATPOA). It somehow seemed cheery in the end - HP gets his Godfather back and all that. There was some cool stuff, including the fact that he gets some real memories of his parents. No. V in comparison is positively depressing. I know life is not fair and all that, but the books could be a bit sunnier. Even Harry's romancing is colored by the fact that his GF is mooning over her dead love. Cut him some slack, will ya?
7. More political allusions. Racism, the KKK and class warfare have all been dealt with. Is it the War On Terror, everyone' s favorite whipping boy this season? I doubt it, because J K Rowling is British. It is only George Lucas who does the whole 'with us, against us' thingie.

I might just sneak into the neighborhood B&N and get a copy sometime soon.


*And Sorry For All The Acronyms.

Monday, July 18, 2005

Smash stack attack!

Warning: Arcane programming terms on the way. Duck to avoid the shrapnel.

This blog started out as a tech/hack blog for me. But then I decided to get up on a soapbox and hold forth.

This is sort of a "return to basics". Non-programming enthusiasts may pass this on. I expect to post more such 'insights'. Interesting little nuggets of programming wisdom gained the hard way - stripping away all proprietary employer-related info. Writing style elements heavily borrowed from Alhad and Larry Ostermann.

So, I was working on this multi-threaded tool at my previous job. I was using the standard UNIX pthreads library. The standard call for creating a thread is:

int pthread_create(pthread_t * thread, const pthread_attr_t * attr, void *(* start_routine) (void), void * arg);

I decided to look it up on my favorite systems-related quick reference book. The example code was something like this:

pthread_create(&tid, NULL, thread, NULL);

Which should have been fine for most purposes. But this is where things get interesting.

The tool I was working on had a set of arguments like this

tool -i inputfile0 -i inputfile1 -i inputfile2 ....

If you entered one input file, the tool would execute just one thing and exit. If you enter multiple input files, the tool would spawn off a thread for each one, and perform a task based on it. It would wait on the threads, and exit when the last one was done. So, inputfile0 causes task0 to be executed, inputfile1 causes task1 to be executed, and so on.

For each task singly, and some combinations of tasks, the tool would work just fine.

For instance, task0 and task1 together worked fine. Task0 and task2, ditto. Task0 and task3, however, busted the thing - segfault.

Trying everything individually worked wonderfully. Task3 was perfect individually. But task3 in a multi-threaded environment just blew up. Everytime. I am happy that the bug at least was reproducible.(Heisenbugs are the worst)

A lot of data on multi-threading was dug up. I went back to the basics, checking to see if all the APIs and objects I was calling were thread-safe. External advice was sought. After having debugged this (IBM dbx, not fun to debug at all. Why can't they use gdb now?) for almost 2 1/2 days, I finally gave up, asking a colleague (the resident dbx guru ) for serious help.

Finally, the solution turned up.

The API uses these large strings of objects to store things. (How large? 64K bytes sound big enough for you? It's actually required. I can't tell you more.) It wasn't something I spent sleepless nights over - I didn't know they used char arrays for such things anymore. What's wrong with pointers? It wasn't my API, and I know I should have asked, but it never struck me. So, every time I passed an object of that in the new thread I was spawning, I was effectively passing in an object of 64K + some other integer and float-type variables.

There were some other API calls involved, which meant my stack was growing large - into 150K+ for sure.

Now, this is not a problem normally. On 32-bit IBM AIX, the stack can grow to 4G without issues.(I'm not so sure about 64-bit)

But, we are in multi-threaded mode here. Aha! The default stack size per thread for a multi-threaded application on IBM AIX is 96K. So, my multi-threaded, multi-call 96K stack was getting smashed - neither for fun nor for profit.

I eat crow. It was my fault. Still, I have to point out - no one I worked with even knew of this gotcha. (At least two other people looked at my code and found it OK). Everyone passes in null as the argument for pthread_attr_t.

In fact, my colleague who helped me debug the issue spent the better part of a half hour debugging it, using arcane debugging commands that I'm sure he conjured out of thin air (I sure didn't see anything like that in the online help)

The solution was of course using a larger sized stack (I think I used 512 K) using pthread_attr_setstacksize. The argument was changed, and voila! Everything was hunky-dory again. Life was good, and there was peace on Middle Earth again.

Lesson Learnt: Never assume any default arguments unless you know pretty well what they imply. And yes, don't trust a student's textbook for the real thing. Real men use Stevens for their programming needs. Even more macho people use man pages only.


1. Threads library options

2. pthread_attr_setstacksize

Friday, July 15, 2005

On names and smelly roses

So, theres this guy on my floor in office whose last name is Gay. I am sure his family took on that name in more innocent and, dare I say it, 'happier' times. It isn't a bad last name to have in the PC world of office and adult conversations. However, imagine having that last name in the cruel world of high school or college. I mean, the South Park crowd use that as a bad word, right next to "weak" and "f*#!ed up".

Having the last name I do did not, thankfully make me the butt of many jokes (pun intended). But, but, but after reading Haroun and The Sea Of Stories, with a pesky bus driver and a robotic hoopoe with the same name, my flat-mates found moi name ripe for harvesting. Being called "The Shah of Blah" on my birthday wasn't too bad - I was a tad too talkative, and they never could keep up. But being a butt of jokes was. I've heard other worse jokes ("Bhat Seriously?").

I am still grateful. If I was from Pakistan or Kashmir, there was a likelihood of my last name being spelled as...you, guessed it, Butt. Imagine what Salman Butt must have been through at high school, especially if he went to one of the fancier "English Medium" schools.

The US does not keep much store by last names. In informal settings, you call people old enough to be your grandfather, and senior enough to be the vice-president by their first names. Imagine meeting the world's richest man on the Microsoft campus someday and saying "Hey Bill". Well, it is possible. It seems to be something that has invaded Indian corporate culture as well. Infoscions I know talk of 'Nandan' . As in Nilekani. CEO. Most of the rest of India, however, still goes by last name.

Nightmare Conversation in college: "Bhat, Why weren't you in class yesterday?" "Um, didnt my friend mark my attendance?" However, I was very low profile in college. I doubt if anyone knew my name. Which was horrendous when it came to getting recommendation letters for grad school. I did have my Andy Warhol minutes, which both helped and hindered.

The transition to first name in the US was hardly smooth. Ajay (as in "a jay jay-walked across the street") is now pronounced Aa-jay. Which is better than AJ. AJ isn't too bad (it's a moniker I used on SMS in India). Only that it's the name of a Backstreet Boys band member (yikes). And it sounds like someone's initials. And it makes my name sound non-Indian. My name is two syllables. How hard can it be?

A rose by any other name would smell as sweet?. Not.

Tuesday, July 12, 2005

The Hard Goodbye

Sin City: Volume 1. One of the episodes on which the movie is based. Kinetic. Graphic. Gruesome. Fun.

Saturday, July 09, 2005

Take the MIT Weblog Survey

Link via JR and Sumedha. Take the survey. Interesting, it is. Hmmm.

The Art of Writing

Sid keeps complaining about people spending too much time on the computer and not meeting people. Well, interacting with like-interested people online can be fun too. I just joined this totally cool web-lahg of people who discuss books and writing. Here is my first post there, a review of William Gibson's Neuromancer.

Friday, July 08, 2005

What have they done to the earth?
What have they done to our fair sister?
Ravaged and plundered and ripped her and bit her
Stuck her with knives in the side of the dawn
And tied her with fences and dragged her down

The Doors - "When the Music's Over"

Monday, July 04, 2005

As one grows older and has a greater variety of experiences in life, does one get blasé and cynical about life? It's something I encounter every once in a while. While the young seem enthusiastic, shocked and outraged, the old seem wise and well, cold to it all. As I grow older, do I try to escape this, or embrace it? After all, the small joys that life has to offer get repetitive after a while. The small and big horrors that life seems to inflict on the less fortunate become everyday.Being horrified by poverty in India is a tourist's indulgence. If you do it on a trip back, be ready to be labelled a firang (a foreigner).

My cousin once told me that there are three Gs that one notices on returning to India from abroad: Garmi (the heat), Gardi (a Marathi word for crowds), and Garibi (poverty). For many of us, it takes a stint abroad in more affluent locales to realize and feel how poor the majority of Indians really are. Staying in India makes a lot of people immune to it (I stand guilty of the charge). Kind of like life itself. The more you live, the less surprises you. So, you need the young.

For it is the young who bring change to the world. If not literally, then the attitude of the young does that. Enthusiasm, outrage, passion are essential qualities to do anything worthwhile to make a change. Tempering that attitude with cynicism and world-weariness only seeks to retain the status quo.

I sense that cynicism about Live8 when I read about it in the papers and elsewhere. The fact is, if you can still be nonchalant about millions dying from starvation in Africa and elsewhere, or by the fact that so many people are affected by floods in Gujarat (supposedly one of India's richest states), something's wrong with you. With me. With all of us. A bumper sticker on a neighbor's car says it best - " If you're not angry, you should be!". Bono's statements seem stilted and pretence at times. You probably expect the kind of statements he makes or the songs he writes ("Peace On Earth"? Dream On!) in a school essay.But he's actually giving a voice to people without one in the affluent world. If not for him or Bob Geldof or the other celebrities with their pet causes, the only consciousness we'll have is when the genocides and famines are all over, millions are dead and Oscar-winning movies are made about them.

There is never a good time or a bad time for doing something worthwhile. The only time is now. One can only do the best one can. But are we doing even that much?