Friday, September 29, 2006

Beware the concurrency monster

Just when you think you know it, you relax a little and the concurrency monster is back with a vengeance! This is a true story...

Once upon a time there lived a lecturer who taught concurrent programming. After years of training and practice he wandered the concurrent landscape with pride and confidence. His offerings to the programming gods had granted him safe travel, and he ventured forth with his new batch of students aiming to get further into the landscape than ever before.

The adventure was going well and one night the lecturer started examining the progress of his young apprentices. While many were doing well they needed a small challenge, something to test the tools they had created. Their latches, semaphores, barriers and exchangers all looked promising, but had remained untested.

"The end of the trek is near, so the challenge must be quickly created." the lecturer thought to himself as he studied their tools. Consulting the dark concurrency forces, he searched for a suitable challenge. Using a cauldron of dread he combined Wing of Interrupt, with Heart of Thread, and a touch of Join dust. In his rush he failed to see the beast that was being created... All day and all night the potion brewed, and on the following day he offered it to his students.


Each student took the potion without question, after all he was the lecturer. The potion was slow, allowing the lecturer to depart before it stirred. Initially the tools held the beast at bay, the Latch stood strong, the Semaphore withheld... then the Barrier was broken, the Exchanger collapsed, and the tools began to fall one after the other. Valiantly the students poured over their code, inspecting it line by line, trying to find the cause of this beast. Their efforts were misguided, none could withstand the beast for it came from the potion, not their code. The concurrency monster leapt from the lecturer's code and roared into existence.

The howling of the beast woke the lecturer with a jolt. Rushing to his students side the lecturer began looking for the cause of this mighty beast. Confident in his code he re-examined the students' code, but one after the other the code was safe. It handled the interrupts, and the many threads, but failed to meet at the join. There could only be one source for this beast... HIS code!

Stepping up to the code, the lecturer went one on one with the beast he had created. The beast was strong, and would not go down without a fight. Code was flying here and there as the beast and lecturer did battle. Minutes later the lecturer rose, covered in code, but triumphant. Returning the tamed test to the students, he stayed around to see if the beast woke again.

His caution was warranted as the second round of tests woke the very same beast. His battle had been in vain. Mustering the last of his strength the lecturer began to mind meld with the beast. Inspecting its structure and form. Searching for its weakness. Then it sprang to him. The timed methods, that can bring these tools back to life. With this new knowledge he reentered the fray and after a few hours had the beast cornered. A quick TryAcquire followed by TryExchange, and the beast went down begging for mercy. Then the final death blow, TryArrive.

With the beast gone (for now) the students returned to testing their utilities. The latches held, the semaphores counted, the barriers stayed strong, and the exchangers once again began to exchange. A cautious peace returned to the world of concurrency. The lecturer once again went back to roaming the concurrency landscape. But the scars from the battle causing him to limp slightly...

So when you next venture into the world of concurrency and pray to the Programming Gods, remember to make an offering to the concurrency monster... just in case.

Wednesday, September 20, 2006

Pollution Death

I have now read the Inconvenient Truth and seen the Movie. I have also read a number of other books on this issue, and feel a little informed. If you want to hear about what James Locklock thinks about this you really need to hear this program from Radio National Science Show. This is a good program, in a really bad way.

Why pollution Death? Read Seth's blog, basically "Global Warming" is too fuzzy and friendly...



I am not quite at despair yet... I believe in putting my money where my mouth is, my actions so far include:
1: Green energy
2: Carbon credits to offset gas usage
3: Energy efficient appliances and light bulbs
4: Fuel efficient car
5: I walk to the train to go to work, unless I really need to drive (currently 1 day a week when I have late classes)
6: I vote and there is nothing more important than this issue
7: Letting others know (22 of us went to the Inconvenient Truth)
8: Turn off appliances I am not using (at the wall, no standby)

Future plans:
1: Buy carbon credits for car and motorbike
2: Buy carbon credits for purchases

Friday, September 08, 2006

Migrating to Mac: Part 5: Mac Apps

Well I have now been using the Mac for a while, and the great thing is that I keep learning new things and finding new and interesting apps. Today I was looking at how to stop Expose trapping the F8 - F12 keys in Parallels, and I came across this blog on Mac apps for people switching from Windows. Its a really good read and I have installed many of the apps that are mentioned. I have also found the following apps quite useful when switching to the Mac.

(Clinton provided the answer for solving my Expose problem... hold down the Apple key when pressing the F key.)

Firefox

While Safari is nice, I just cant get by without my Firefox plugins. Firefox runs well unders MacOS... so there are no problems here.


Muvo Helper

The MuVo Helper is a small utility that performs background tasks for Creative MP3 Players like my Zen Neeon. While not essential, it is a nice addon. Basically it sits in the background removing the extra files that MacOs copies onto the device as you add music to it.

Menu Meters

Clinton brought this one to my attention. This little app installs menu bar icons to show computer activity such as disk, cpu, memory, and network usage. A real must have for anyone wanting to know what is currently happening in their Mac.

xCHM

Another gem from Clinton's blog. This utility allows you to read the Microsoft help files on the Mac. Great for when you are writing code in Parallels. The code is shown on one screen in Parallels, and the documentation can be open on the Mac on another screen.

Aquamacs

Aquamacs is emacs for the Mac. It includes both emacs shortcuts as well as standard MacOs shortcuts. This works well for me...


Booxter

This is a funky little library application, allowing you to keep track of your personal library. It has features to track who has borrowed your books, and can import details from various web sites such as Amazon. The ability to scan books using the Mac's built in camera is also neat... though I have found it doesn't pick up the details that easily.

Poseidon for UML

I needed a tool for drawing UML diagrams, and this did the trick. It is a little clunky to use, though I haven't spent much time with it at the moment. This is a full UML tools keeping track of the model, so with some reverse engineering support it should be good. There is a free community edition.

iTerm

An alternative terminal program that allows terminals in tabs... Quite a nice alternative to the standard terminal.

Monday, September 04, 2006

Documenting C# Projects

Playing around with .NET 2.0 and Visual Studio .NET 2005 has left me asking what do I need to communicate with my designs. The class diagrams in Visual Studio are very elegant, and remove my desire for creating UML class diagrams once I start playing around with a solution. UML class diagrams are great for modelling problem space, and thinking pre-solution, but one I start thinking solution I am now heading to VS for my diagrams.

There are a few things missing from the VS diagram that do cause me some headaches.
1: Dependency. It would be great to be able to show dependency type relations in the diagram.
2: Lack of diagrams to represent object dynamics.

I have voted on the first item on the MS feedback regarding VS.

On the second point I am still using UML diagrams to describe these. Visio has been my UML tool in the past, though it is challenging to use. Today I started playing around with Poseidon for UML. Looks like it has potential, but it does not support reading in class details from C# code... Examining the list of features it does support shows XMI, so I started looking for a tool to convert my C# code into XMI, and I found the following freeware. The DotNet Assembly to XMI Creator 2.1 tool is able to convert .NET assemblies into XMI according to its documentation. Unfortunatly the product does not support .NET 2 assemblies... nice try :(

An open solution to this would be nice... I have created a quick open source library to do this called xmi4dotnet. I have hosted it on google to allow access to the source. I will also setup a game for it at sometime on SwinBrain. This tool allows you to export xmi code from .NET assemblies. It uses the Reflector tool to examine the model and loads into this tool as an addin. It exports all the different .NET types as well as fields, properties, etc. I have tested the export and the xmi can be loaded into Poseidon. Try it out and let me know any changes you want made (use the bug tracker on the google code hosting page).

Microsoft Recruiting in AU

Microsoft is recruiting developers in Australia again. If you are finishing your degree this year, or have already finished, you may want to apply...