Being Bit(ten) and Byting Back

Monday, May 30, 2005

The Lock Statement in C#....

Need to remember this From MSDN ... lock(x); is precisely equivalent to in C# ... System.Threading.Monitor.Enter(x); try{

//...

}catch {

//...

} finally{

System.Threading.Exit(x);

} and in C++/ System::Thread::Monitor::Enter(x); try{ } __finally{

System::Threading::Monitor::Exit(x);

}

Apple - QuickTime - HD Gallery - Serenity

Apple - QuickTime - HD Gallery - Serenity: Its official, I am now a fan of Firefly, and looking forward to the movie.

Something to remember about deadlocks

Somebody once said to me that "In theory, theory and practice go together. In practice, they rarely do.".

Yesterday, while working on interfacing module for a digital radiography panel we use in our product (Yes, I was working over long weekend. And I need some sympathy please!:'( ), I ran into one of those rare situations where forgetting your OS theory is detrimental to your long-term sanity.

I ran into a very subtle situation where two of the three threads were deadlocking and freezing up the application. I don't want to rehash the whole story here, the memory is too raw and painful right now. I figured out in the end what was going on after a couple of hours when I saw some undergrad notes on an OS course on some CS department on deadlocks. And I cursed myself for not remembering those. OS theory was always something that bored me, and yesterday I wished I had paid more attention in class.

So what I'm going to do now is to write those conditions on my blog, in the faint hope that I can remember them the next time I'm working on a long weekend thinking about the beautiful day outside. The three conditions for a deadlock to occur are: [drum roll here] i) Mutual Exclusion: Only one resource may use a resource at a time. ii) Hold-and-Wait: A process may hold allocated resources while awaiting assignment of others iii) No Pre-emption: No resource can be forcibly removed from a process holding it.

Now, in a multithreaded application, these conditions are good thing, however, if the fourth condition is satisfied, then you're locked in the deadly embrace of death

iv) Circular Wait: A closed chain of processes exists, such that each process holds at least one resource needed by the next process in the chain.

On another note, I've always wondered if there is a better way to design a multithreaded application in OO context. A thread is a thread of execution and somehow that's always smelled of a procedural function to me. The question I have is that in a well-designed OO design, should'nt all objects be active, and all messages asynchronous?

Friday, May 27, 2005

The Old New Thing : When is x/2 different from x>>1?

The Old New Thing : When is x/2 different from x>>1? This is an interesting point. I always thought it was a good optimization. I never considered what the effect would be on negative numbers. The moral of the story is right though. Its always a better idea to write what you mean first and then fiddle around with various optimizations later when doing code reviews or something.

Wednesday, May 25, 2005

Bug Bash

Bug Bash: Here's something I discovered today. A new comic strip for Geeks by a geek.

Saturday, May 21, 2005

About Movies, Music and other Mundane things today...

First about “Revenge of the Sith”... Finally saw Star Wars Episode III. I was'nt able to go see the movie on opening night at the Carousel Mall like I had originally planned too. It was just too late in the evening. I heard from some of the coops at the office that the fans over there were in full Star Wars regalia. I'd like to have seen that.

So what did I think of the “ROTS”? It was certainly better than AOTC and TPM. If I were to rank them in order of how I like them, it would be something like this. 1. The Empire Strikes Back 2. The Return of the Jedi. 3. A New Hope, The Revenge of the Sith (tied for 3rd place). 4. Attack of the Clones 5. The Phantom Menace.

The woodenness of the characters was still there. but the visuals and acting especially of the Anakin Skywalker was very dark, which was surprising considering that this is a movie that likes to have furry and cuddly creatures. Think Ewoks, Wookies, and Jabba the Hut. Okay, maybe not Jabba the Hutt. Jar-Jar Binks was also a candidate of the list, but I decided to exclude him from the list. Personally, I think he was one of the most annoying characters of the prequels.

One of the nice things, the movie had was the appearance of Chewbacca. I thought that was a little necessary, to bring that Han Solo link in the movie. I was hoping that they would have a Han Solo role in the movie, since I always thought his was the best role in the movie.

Another thing that I found interesting was the fact that in every direct engagement with the Jedis, the Sith lords are defeated in this movie. Mace Windu almost killed Palpatine, had it not been for Anakin, and then the final fights with Yoda vs. Palpatine, and Anakin/Vader vs. Kenobi. So if the Sith were so powerful, how come when it came to facing off the real masters (Yoda, Mace Windu, Obi-Wan Kenobi) they were a bunch of losers. I guess the Lucas' wanted to emphasize that no matter how solid a victory the bad guys achieve, its only temporary. The good guys always win in the end.

There was a lot of dialog in the movie that seemed to be gleaned off current events. People who follow the news must have seen the parallels. I'm not going to comment on that because as a rule I do'nt do that on this blog, but its pretty obvious where George Lucas' political leanings are.

The film also a explains why R2D2 and C3PO have no recollection of Anakin and Tatooine. That's because Senator Bail Organa has C3PO to be memory wiped. I guess its because of the fact that Anakin had constructed C3PO. I'm not so sure about R2D2. Was he memory wiped or not. I guess I'll have to get the book adaptation of the movie. I saw that in Barnes and Noble last night.

I thought that the Anakin/Vader 's hysterics at the end of the movie were a little over the top, but thats understandable. The man lost his wife and kids. What do you expect? But I liked the part where Anakin/Vader talks to Padme on to Mustaphar (<--did I get that right?) and tells her that he can take over the Republic and depose the emperor. He uses the same line with Luke in Empire Strikes Back. This raises an interesting question. Was Anakin really looking for a chance to rule with his family. We all seem to think Anakin had turned to evil and all, but was it really evil? It could have been a means to an end where he could finally get the power that he need to bring his visions of better world (well galaxy in his case). Am I being a moral relativist here?

If you look at the whole Star Wars thing objectively, you have to admit that the Empire did bring order and peace to the Galaxy, and instead of the cronyism of the Republic, the Emperor established a real meritocracy. I'm sure readers will remember that Boba Fett addressed Han Solo with a respectful “Captain Solo”, since Han Solo was an ex-Imperial Officer candidate. The only bad thing about the Empire, I think was that they were a human centric culture, meaning that they preferred humans over non-human cultures and races. I guess there are many people who would prefer that sort of setup

Well now that we've met all the various Sith Lords, who was my favorite Sith Lord. I think Darth Maul was the coolest Sith Lord. The crown of horns, tatooed face, flaming eyes, and menacing teeth were really amazing. Gave him that look that said, I'm a mean m^&*&^**&f*&%&^%&%. I wish they had given Darth Maul a more prominent role, through the episodes.

Darth Vader, had this regal powerful bearing about him, that sort of portrayed power. His personality was an extremely controlling and imposed itself.

Count Dooku (Darth Tyranus) looked and sounded like a stop-gap arrangement.

Darth Sidious, seemed to be more of a string puller then a real warrior.

Thats about it on what I have to say about Episode III. Comments are welcome.

On to other things.... Just discovered a new band called “Mere”. Some very nice music. Click here to visit the site. They've got some sample songs, and some songs can be bought of PayPal.

Currently listening too.

dont_want_to_be_saved by Mere Anything at All by Mere

Saving your Regrets by Mere (this is a good one)

Black to White to Gray by Mere

Friday, May 20, 2005

Musings for the day....

My apartment is a mess!! My neighbor upstairs, is really excited about something. He or she has been stomping all over the place since I came home from work! Needless to say it's driving me nuts. Currently Listening to... A Favor House Atlantic from the album "In Keeping Secrets of Silent Earth: 3" by Coheed and Cambria Speed of Sound from the album "Speed of Sound - Single" by Coldplay There album is coming out soon! Currently reading (again) "Life of Pi" (Yann Martel)