Thu, 05 May 2005
Multithreaded Programming w/ Delphi 5 on Windows XP
I have successfully solved a very nasty little programming problem which only appears to show up under Windows XP. First, a little backround: At my work, we provide loan calculation libraries to other parties, for use in their systems. One of our potential customers requested that we prove that our 32-bit Windows library is thread safe.
I knew that the library (written in Delphi 5) was currently not thread safe (it wasn't written by me!), but estimated that I could get it up to snuff in about a day or two. Before 'fixing' the library, I set out first of all to write a multithreaded client to prove that it was not thread safe. That way, I could then fix the DLL and then re-run the tests, hopefully proving that what was once broken was now fixed, etc.
Delphi is a great language to program in. It is object oriented, with full support for all the OOP buzzwords like: polymorphism, information hiding, etc. Couple that with a great support library and a lightning quick compiler, and you have a very great combination. So, I quickly whipped up an application that spawns 4 worker threads, each of which compute a different loan 4000 times. Each time through the calculation loop, it checks to see if the results returned from the thread-unsafe library have changed from the correct, base line results computed in a single thread at application initialization.
As expected, the app crashes hard with EInvalidPointer exceptions, etc. It is ugly indeed. So, I then go into the DLL and strategically place some critical sections to protect the vulnerable areas, and then run the multithreaded test again. And it still doesn't work. However, it DOES work on Windows boxes of the flavors 98 and 2000. Very odd.
It is hear that my 40 days in the programming wilderness begins. I write a second, simpler console based multithreaded client in the thoughts that perhaps the vcl thread was creating problems. That didn't do the trick. I simplified the test apps as much as possible, with no luck.
After three days of pounding my head against this programming brick wall, scouring the net via Google, I stumbled upon a reference to a global variable names IsMultiThread, supposedly set up by Delphi in System.pas. This variable is supposed to be automatically set to true whenever you use Delphi's TThread object, and one would guess that it should also be set for DLL projects. I decided to explicitly set this variable to True in the initialization section of the DLL, as well as in the test applications startup.
EUREKA! The problem was solved, and I was able to rest over the weekend. Except that 2 out of 3 kids were sick, but that is an entirely different saga. So, the moral of the story is that when writing a multithreaded library or application in Delphi 5, just go ahead and explicitly set IsMultiThread := true. I hope this post can help someone avoid the same problem again!
posted at: 11:42 | path: /computers/programming | permanent link to this entry
Tue, 08 Feb 2005
Google Maps!
Google Maps has just opened its doors as of today. Currently, it it fairly javascript heavy and only works well in Mozilla browsers (including Firefox) and Internet Exploder. Looks pretty slick, at least as far as my brief test can tell.
posted at: 15:46 | path: /computers | permanent link to this entry
Fri, 28 Jan 2005
Hotplug Support for Everyone in Debian Sarge
Over my vacation, I put together a new system at home consisting of: AMD Sempron 2500+, 512MB ram, 120MB 7200rpm drive, old GeForce2MX graphics card, and a new case w/ USB ports in the front. I decided to set it up in a dual boot configuration: Windows XP for gaming, and Debian Linux for everything else.
Debian's new installer project is paying off with a very slick system. The only thing I didn't realize until after the installation was that the default kernel to install was 2.4. There is a boot option to install a 2.6 kernel, but I missed it. No biggie, a simple "apt-get install kernel-image-2.6-k7" solved that particular problem, and everything seemed to be running smooth as silk. Sound, networking, etc. - everything just worked. Very nice, and an easier install than Windows XP.
However, I did have one stumbling block which I had to overcome. For some reason, I couldn't get the gnome desktop to recognize my USB mass storage device once it was plugged in. Checking the output from dmesg showed that it was being correctly recognized and set up, so it must have been something else. Logging in as root, I descovered that it worked fine. This fact zeroes the problem down to one of permissions. There is a permission that normal users on the system need to have in order to be able to mount the flash drive in question.
After looking at the /etc/group file, I saw a group named 'plugdev', which appeared promising. Using Google (aka the index to the internet), I verified that this was a likely cause to my problems, and added my 'normal' user account to the group. Bang - zoom, the problem was solved!
And so I write this post, hoping that I might be able to help someone else out having the same problem I did, and at the same time recording it down for myself in case of future use!
posted at: 19:20 | path: /computers | permanent link to this entry
Mon, 17 Jan 2005
Free Antivirus Software for the Home?
Many people spend way too much money for antivirus software which some companies turn into bloated, resource draining suites. If you want to try something different, give Avast! Home Edition a look. It is completely free for home, non-commercial use.
posted at: 15:36 | path: /computers | permanent link to this entry
Wed, 24 Nov 2004
Progeny Debian Developer Edition RC1
My Debian SID (still in development) installation on my home PC has been acting up for a while now, but not enough to force me to reinstall and go through the whole process of setting things up just right. A few days ago, I checked out the SUSE Linux 9.2 live CD, and was fairly impressed with it. Unfortunately, Novell/SUSE has not yet placed the full distribution on their ftp servers, so I began looking elsewhere.
The next day, I saw that OSDir.com had a brief article with an extensive screenshot gallery posted showing Progeny's Debian Developer Edition, Release Candidate 1. Since Debian is probably my favorite distribution I've used to date, I figured that I would give it a shot and proceeded to download the two CD images containing the required installation files.
To make a long story shorter, I deleted all files on my existing linux partition except for the /home and /etc directories, and renamed them /home_old and /etc_old. I kept the home directory since it contains all of the user data and files, whereas /etc contains lots of setup information that I thought I might need after the installation.
The 2 CD installation proceeded smoothly, although the actual process of copying the package contents to the system seemed to take a while. This could be due to the CD-R media the iso images were written upon, but I'm not sure. After the installation was completed, I rebooted the system and ... nothing. Crap!
I messed around with the grub boot loader options, and nothing I tried seemed to improve matters. I then moved my hard drive from /dev/hde to /dev/hdc, thinking that perhaps the kernel was having problems accessing ide3. After tweaking grub to try and load the kernel from /dev/hdc and removing the silent boot option, I got a crc error in the initial stages of loading the kernel. So, I figured that I would try to install it one more time.
Roughly 1.5 hours later, the system was installed (again), and the moment of truth arrived as the machine rebooted. This time, the system came up with no detectable problems! Woo-hoo!
My initial thoughts on the system after a paltry hour of use is that the distribution is clean, functional, and nice. I installed the workstation version to get all of the development tools installed along with the normal desktop apps. Gnome is the desktop environment installed, with Evolution as the mail client, Firefox RC1 as the web browser, and OpenOffice 1.2 as the office productivity suite. As a first impression of the distribution, I'd have to give it two thumbs up. I am sure that as I use it more, my opinion will be refined depending upon what problems/gems I encounter.
posted at: 09:11 | path: /computers | permanent link to this entry