| < | May 2005 | > | ||||
| Su | Mo | Tu | We | Th | Fr | Sa |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | ||||
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!
May 05, 2005 11:42 | [ ] | # | G | Comments (0)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!
Jul 12, 2004 10:14 | [ /python ] | # | G | Comments (0)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.
Jul 02, 2004 14:41 | [ /java ] | # | G | Comments (0)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.
Feb 06, 2004 08:22 | [ ] | # | G | Comments (0)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...
Oct 08, 2003 13:15 | [ ] | # | G | Comments (0)Today, I was looking over a Delphi project which my company is close to marketing, trying to find a way to make it quicker when initially loading up the various settings (hundreds of them) from the INI files. The product functions as expected, and is fairly complete, so now is a good time to start looking at optimizations which will increase the number of calculations per second (one of Knuth's laws: premature optimization is the root of all evil).
I figured that the TINIFile object implemented by Delphi was merely a thin wrapper around the INI file related Windows API functions. I thought that I could perhaps write my own INI file object which would perhaps cache the file in memory, thus reducing disk I/O and hence, increasing performance. Checking out the source code for the TINIFile object confirmed my guesstimation, and provided a pleasant surprise as well. In the same INIFiles unit which defines the TINIFile object, another object called TMemINIFile is defined. The implementation of this class cached the INI file in memory, just as I had planned on doing.
To make a long story somewhat longer, I merely replaced references of TINIFile to TMemINIFile in all of the units where INI files are used, and the performace of the project increased by more than a factor of 8. Woo-hoo! Now that is the kind of optimization that I like...
Jul 02, 2003 19:25 | [ ] | # | G | Comments (0)A few people have requested the source code for the chat server I mentioned about a week ago, so I bit the bullet and cleaned up the code a bit, wrote a README file for it, and here it is.
In the not too distant future, I plan on adding several features to it, such as multiple rooms, user lists, etc. Any comments and/or suggestions are always welcome! Furthermore, my chat server on port 2500 of www.shermanloan.com is still up.
Jun 17, 2003 09:45 | [ /python ] | # | G | Comments (0)Well, I have finished the beta version of the chat program I mentioned yesterday. If you would like to give it a whirl, either use telnet or a MUD client and connect to www.shermanloan.com on port 2500. It is fairly rough around the edges, and sports a modest feature set:
I will be adding some more features to the chat server in the very near future, such as multiple chat rooms and private messages. Eventually, I will be expanding this into some sort of MUD.
If anyone is interested in the code to the server, drop me an email and I'll be happy to put it up for your downloading pleasure.
Jun 06, 2003 14:50 | [ /python ] | # | G | Comments (4)Python is a programming language which is interpreted, object-oriented and interactive. It is considered a high level language, most often compared to Perl, Tcl and Java. There are many excellent introductions to Python (both free and non-free), but I would recommend How to Think Like a Computer Scientist - Learning with Python as a great starting place. The Python for Beginners area of python.org contains many other on-line tutorials to sink your teeth into, if you so desire.
When learning a new language, I find it helpful to try and target a project and then dive into the language, trying to implement the project in the new language. Seeing as how python has a vast library of routines, I have decided to target a project involving non-trivial networking(a first for me). The first stage of the project will be a chat server, which will allow numerous connections from client machines (via telnet) and that will take the text sent by each client to the server and echo it to all connected clients (think IRC with one room, I guess).
In order to implement the chat server, I am using the asyncore and asynchat modules of the Python 2.2.3 library. Both of these modules originated in the Medusa project, which "is an architecture for building long-running, high-performance network servers in Python."
I should have the chat server completed in the next few days, and when I do, I'll post the information (and source code) here for all to browse.
Jun 04, 2003 14:07 | [ /python ] | # | G | Comments (2)I spent some time working in the Eclipse environment today, checking out it's features and performance. So far, I am very pleased with it. IBM has something very nice here, so check it out if Java or C is your thing.
Here is a picture of the Eclipse IDE with the RallyCar I am toying with and learning Java at the same time. Click on the thumbnail image for a larger version.
May 07, 2003 14:27 | [ /java ] | # | G | Comments (0)If you are considering learning how to program in Java, then CodeRally and the Eclipse platform would make a good start.
Code Rally is a programming game where you attempt to program a rally car to beat other rally cars. By altering a few lines of code you can change the behavior of your rally car, and hopefully improve its performace.
May 06, 2003 14:50 | [ /java ] | # | G | Comments (0)