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

Mon, 12 Jul 2004

Python Development with Eclipse

As reported here earlier, Eclipse 3.0 was recently released to the computing public. While Eclipse is viewed primarilly as an integrated development environment for the Java programming language, it is actually far more flexible. The Eclipse Foundation has positioned Eclipse as a general purpose IDE, where plugins for each supported language are needed to cater to the language's specific needs. Therefore, the Java IDE is a separate package from Eclipse, etc.

To develop in Python with Eclipse, read through this article, from the folks at IBM developerworks. It discusses how to download and install the Python IDE plugin, and then goes over some of its features. Very cool!

posted at: 10:14 | path: /computers/programming/python | permanent link to this entry

Fri, 02 Jul 2004

Eclipse 3.0 Released and More Java Fun!

The Eclipse Foundation has released version 3.0 of the Eclipse IDE. This release debuts run-time binary compilations of the IDE for increased performance, as well as all kinds of new features. Download it and be merry!

Once you've downloaded and installed the new version, try your hand at CodeRuler, a graphical simulator designed to exercise your Java programming skills. Download CodeRuler here.

posted at: 14:41 | path: /computers/programming/java | permanent link to this entry

Fri, 06 Feb 2004

Programming Linux Socets

IBM's DeveloperWorks Tutorials site is a great site to keep your eye on if you are a computer programmer. They cover topics which range from Java to Python, XML to web services, etc. Note that to access the tutorials and other articles on the site, you must first go through a quick (and free!) registration process, which is well worth the effort.

As an example of what you can find there, take a look at this introduction to Programming in Linux Sockets, Part 1. This introduction starts out with the basics of IP networks and network layers, and then proceeds to show you how to applications which utilize these parts in C and Python.

posted at: 08:22 | path: /computers/programming | permanent link to this entry

Wed, 08 Oct 2003

The Art of Unix Programming

I just wanted to point out a book which has recently been released by Eric Raymond. The title of his new book is The Art of Unix Programming, and an HTML version is available for one to peruse online. Of course, he would appreciate it if you bought a printed copy if you like it, but there's no obligation to buy (or so those salesmen always tell me).

From the preface:

This book has a lot of knowledge in it, but it is mainly about expertise. It is going to try to teach you the things about Unix development that Unix experts know, but aren't aware that they know. It is therefore less about technicalia and more about shared culture than most Unix books - both explicit and implicit culture, both conscious and unconscious traditions. It is not a 'how-to' book, it is a 'why-to' book.

So check it out and give it a good look-over. I plan on doing so myself...

posted at: 13:15 | path: /computers/programming | permanent link to this entry