Monday, June 07, 2004

The Double-check Locking Idiom is broken

After reading Raymond Chen's very insightful blog a couple of nights ago, I couldn't resist investigating the Double Check lock idiom on the Internet. There is a whole bunch of literature on the topic but here is a quick introduction. In today's world of multi-processor machines, synchronization has become one of the biggest headaches for systems programmers. There is also the added need to make code run as fast as possible, therefore, reducing the size of critical sections and number of acquisitions of mutexes/locks/semaphores (since acquiring a lock is an expensive operation in terms of time, the cache and the pipeline). Sometime in 1996, Doug Lea came up with this idea for creating a Singleton (refer the GoF book on Design Patterns) but making the code acquire the lock only once and return the instance in the most commonly encountered codepath. Here is a code sample in Java:
class Foo { 

private Helper helper = null;
public Helper getHelper() {
if (helper == null)
synchronized(this) {
if (helper == null)
helper = new Helper();
}
return helper;
}
}

It was later determined that this code breaks in the case where the compiler optimizes instructions within the synchronized block such that a consumer of the helper instance might see non-initialized members in the object.

The "Double-Checked Locking is Broken" Declaration paper provides insight into why the algorithm is broken and a possible way of fixing it. The way to solve this in Windows will be the topic of another blog post. In the interim, feel free to post any solutions that you think will solve the problem.

Saturday, June 05, 2004

The Countdown to 160lbs begins today

My trip to India this time around was an eye-opener for more reasons than one. I saw pictures of my college days and the one striking difference between me then and me now (outside of me being hairier where it matters) is the fact that I was lean and fighting fit - 12 lbs is a lot to put on in 5 years. My medical records indicate no increase in body weight till the last year in which I put on the aforementioned evil 12 lbs. Some of the weight can be attributed to an increase in muscle mass (no boasting, but my body fat % is a low 11.8%) but there is definitely fat where there wasn't any earlier...

So what can I attribute this sudden gain in weight to - squarely on wanton eating. There used to be a time when I was very careful about what I ate and when I ate it - not anymore. I've eaten meals after midnight twice in a row and that's only the story this past week. Add to that shorter and more sporadic workouts and there you have it - a fatter Manoj. So today, I've decided to take a stand. Better eating, more regular workouts and I should hit my target. I'll update this space every week with my progress...

BBC NEWS | Technology | Microsoft bars Windows pirates

I'll post an update with the exact number of hours hackers will take to crack this check...

Friday, June 04, 2004

Sun: No decision on open-source Java

Contrary to the reports published on News websites and prominently linked to by Slashdot, Sun hasn't made any decision on whether it wants to Open Source Java.
On Friday, Gosling confirmed that Sun had still not made a decision on whether or not to open-source Java. "Despite any of the articles, the debate is still going on, fast and furious," he said via e-mail.
There was a time when I was an avid Java programmer but not being in touch with the language for 2 years has made my knowledge archaic. I owe a lot to my years programming in Java though, the depth of Object Oriented programming skills I acquired by learning, reading and experimenting in Java is immeasurable. I for one am not in favour of the language being open sourced because from my experience with Open Source, more is said and less is done. And with a few exceptions, customer focus is nearly non-existent. What Java needs is direction right now in its fight for survival against the C# and .Net juggernaut, not randomization and anarchy...

Wired News: Windows XP Bedevils Wi-Fi Users

This article might explain why your Wireless connection suddenly seems to not "work" even though the Network Icon in the System Tray indicates that everything is fine and dandy :) It's easy to point fingers and pin the blame on Windows and the Wireless Zero Config service but this isn't conclusive. The article, for once, helps users disable the service even though it suggests that users rely on the software provided by the Hardware manufacturer - nice try!! I have friends on the Wireless Networking team so I'm going to investigate this further but as someone who has been bitten by this in the past, I'm going to try the solution proposed and see what happens to my Wireless connection...

Thursday, June 03, 2004

Yoga and I

My first experience with yoga was with Nikhil during my last vacation in Bombay. Having seen people do the various poses, in utter disbelief I might add, on the television and reading numerous articles about the huge following yoga commands in the Western World, I decided to take the plunge too. And let me tell you this, it's not for weenies...

There was more than one occassion during today's class when I felt over-whelmed by the endurance required by a pose. Even though the poses took so much effort, I surprisingly felt very relaxed at the end of the hour long session. The combination of the teacher's soothing voice and the mellow music has proved to be the undoing for many but I resisted the temptation to nod off ;) And there was no role call taken, something I liked because the teacher had the implicit faith that a person wouldn't be at peace if they crashed the class - misguided you think? All said and done, I'm going to try to be a regular at the sessions...

Tuesday, June 01, 2004

Is the PDA Dead - Sony Exits U.S. Handheld Market

I've wanted to own a PDA for a year now but can't seem to justify the utility of the device, therefore can't overcome the inertia to go buy one. This article might actually be impetus enough because right now, Sony's PDAs will be going CHEAPppp :)