People don’t write enough multi-threaded code

There’s an article on Computerworld that Microsoft is telling us that multicore chips are changing PC software design, but that not enough people are programming multi-threaded applications to take advantage of this feature.
Let me tell you, writing multi-threaded code is really easy. Writing correct multi-threaded code is the tricky part. Most development frameworks are not Multi-Thread safe. This means that you can’t use it willy-nilly from multiple threads at the same time (it’s primarily a resource assignment issue). So you have one thread that performs all the GUI work. Then you have to coordinate to have either the data or something close to rendered detail for the GUI thread. Then you have a barrage of threads performing various other bits of work. Of course, don’t forget that making an application too multi-threaded has negative effects.
There is a subtle difference between multi-processor and multi-threaded processors which means that an mt-processor isn’t the same functionally as separate cores/processors (shared resources, this being the whole -threading implication behind the name), so just throwing arbitrarily extra work at the mt-processor won’t gain you much. The OS needs to know this information to schedule more intelligently, so adorning the threads with informatiion about the related data-affinity can gain you significant performance boosts (the OS schedules different threads more intelligently). The problem is that you need to export this concept to an application programmer. Guess what, it’s generally too complicated for anything less than the most processor intensive tasks.
Generally, having the extra threads/cores/processors means that you get an overall system performance boost, it’s just that the OS stops the isolation granularity at the process level. Operating systems have been designed around the ‘complicated process, simple thread’ principle. You don’t want to change the balance of complexity moving back into the threads, we’ll just end up with a sub-thread concept, and my head just hurts from that (atoms, quantum elements).
So what does the average joe programmer do? How do you find places that are suitable for parallelizing? How do you then ‘fix’ them up? Well, unless your program needs parallelism in the first place, it’s actually difficult to retrofit it into a pre-existing design.
Well, there’s a ton more stuff on this that I would like to get down, but it’s 2am, and I need to get some sleep. More in the morrow.

Annoying Delphi 2005 OTA issue

Well, this one is just lovely. The first problem is that it does not support introspecting the Environment Option Names. This is annoying, but the next issue makes it even more fun. When we go looking for the options for, for example the package output directory variable (PackageDPLOutput) it looks at the .NET version before looking at the win32 version i.e. it’s got overloaded option names.
Oh well, it will need to be worked around again, I suppose.

[Listening to: SSREP13 The Veldt – Andy Doan – Spaceship Radio (29:48)]

Page Style Chooser

I put in the ‘set page style’ options on the right hand side of the page. They seem to work just fine, mind you there is also the choice in the View->Page Style menu option in Firefox. I’m going to have to change some of the styles to make them more fluid.
I like fluid pages – I tend to resize and get annoyed when they only occupy a small portion of the screen.

How to steal focus on 2K/XP

You used to use SetForegroundWindow, but that only blinks your window now, this is because stealing focus is evil. It can be done and it’s evil.
You use the AttachThreadInput API call. The process is attach, focus, detach.

AttachThreadInput(GetWindowThreadProcessId(
GetForegroundWindow(), NULL),
GetCurrentThreadId(), TRUE);
SetForegroundWindow(hWnd);
AttachThreadInput(GetWindowThreadProcessId(
GetForegroundWindow(), NULL),
GetCurrentThreadId(), FALSE);

Again, this is doable, the problem is that it’s not good UI design as this will make your window focus even if your application wasn’t in the foreground, which as we all know is a no-no.

[Listening to: Purple Haze – Groove Armada – The Best of Groove Armada (4:03)]

Default make rules

The default make rules for solaris are in a configuration file. This file is /usr/share/lib/make/make.rules
gnu make wanders around with the file built in. You use gmake -p to get it’s default rules (and a whole load more besides).

Don’t forget to cast (a.k.a. 1 / 5 = 0)

You would think that people would remember this. C keeps things as an integer unless you tell it otherwise. This means that unless you tell the computer otherwise, it will keep blithely working on integers. so to get a proper answer cast one of the values to a float, and the entire operation gets done as a floating point operation.
Simple rules for simple languages.

First rule of profiling

The first rule of profiling is that by profiling you change the behaviour of a system. This can mean intermittent bugs, performance slowdowns, or general wierdness. Nothing earth shattering, but you just have to keep reminding yourself of it occasionally.

[Listening to: The Lion and the Cucumber (The Doctor and the Rockit Remix) – Dr Rockit – The Spirit of Vampyros Lesbos (5:48)]

New GroupLayout manager run time exception prevention

Just a hint for those who might forget, because the new layout manager is not standard in Java, you need to make sure that your application ships with the new layout code in tow. To find the location of this layout manager on your system, open the library manager and look for the ‘Swing Layout Extensions’ library. This will give you a pointer to the .jar file needed to run under the new layout manager. In my case that’s J:\Program Files\netbeans-5.0beta\ide6\modules\ext\swing-layout-0.7.jar, Your jar file name and directory mileage may vary.
java.lang.NoClassDefFoundError: org/jdesktop/layout/GroupLayout$Group. Then again if you don’t know why the error is happening I’m slightly shocked.

[Listening to: Little Earthquakes – Tori Amos – Little Earthquakes (6:52)]

Now here’s something that really kicks ass…

image of the layout manager

The new layout manager for the Netbeans 5 designer. This form designer kicks ass on so many levels. It’s really quick and easy to get things into the correct places without having to worry about baglayouts within flowlayouts within gridbaglayouts. Truly a joy to make use of.

[Listening to: U Boat – Kasabian – Kasabian (10:50)]

Good old PromptDataSource

This one makes building ADO connection strings in client applications very easy. PromptDataSource is a member of the IDBPromptInitialize COM object. Creating it involves a small bit of C++ code:

IDBInitialize *pIDBInitialize = NULL;
IDataInitialize *pIDataInitialize = NULL;
IDBPromptInitialize *pIDBPromptInitialize = NULL;
LPOLESTR strConn;
CoCreateInstance(CLSID_DataLinks, NULL, CLSCTX_INPROC_SERVER, IID_IDataInitialize,
(void **)&pIDataInitialize);
CoCreateInstance(CLSID_DataLinks, NULL, CLSCTX_INPROC_SERVER,
IID_IDBPromptInitialize, (void **)&pIDBPromptInitialize);
pIDBPromptInitialize->PromptDataSource(NULL, 0,
DBPROMPTOPTIONS_PROPERTYSHEET, 0, NULL, NULL, IID_IDBInitialize,
(IUnknown **)&pIDBInitialize);
pIDBInitialize->Initialize();
pIDataInitialize->GetInitializationString(pIDBInitialize, true, &strConn);

There are no checks anywhere here! You should add your own. C# makes things quite a bit easier.

MSDASC.DataLinks oDL = new MSDASC.DataLinksClass();
ADODB.Connection conn = new ADODB.ConnectionClass();
conn.ConnectionString = "Provider=sqloledb";
object oConn = (object)conn;
oDL.PromptEdit(ref oConn);
OleDbConnection xconn = new OleDbConnection(conn.ConnectionString);
xconn.Open();

Of course, you need to add a reference to the com types: ‘Microsoft ActiveX Data Objects 2.8 Library’, and ‘Microsoft OLE DB Service Component 1.0 Type Library’, which provide access to the MSDASC and ADODB COM objects. You just extricate the Connection string at the end. I’m explicitly setting the provider in the second instance as I’m lazy, and I’m always accessing sqloledb. The 2.0 .NET framework may introduce an easier mechanism for doing this.