<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Delphi</title>
        <link>http://nimblecoder.com/blog/category/10.aspx</link>
        <description>Borland Delphi</description>
        <language>en-US</language>
        <copyright>Ryan Van Slooten</copyright>
        <generator>Subtext Version 2.1.1.1</generator>
        <item>
            <title>Do You Remember All of Your Command-line Parameters?</title>
            <link>http://nimblecoder.com/blog/archive/2007/09/28/do-you-remember-all-of-your-command-line-parameters.aspx</link>
            <description>&lt;p&gt;I had to brush up on my command-line parameters for cl, link, lib, and dumpbin today. It had been a little while since I had done this so I had to refresh my memory. The project dealt with a DLL generated by Delphi (the original source language was closest to Pascal/Delphi so I wrote a utility to convert Pascal rather than doing a massive conversion) and also generated C headers files and C unit test files at the same time. A while back they wanted a new DLL for a different project that used different functions from the original source. I was quite busy on another project but found enough time to make the new DLL. There was a problem with the initialization of one of the functions though.&lt;/p&gt; &lt;p&gt;In order to debug, I compiled the unit test but it wouldn't link directly to the DLL. I had to generate the .LIB and .EXP from the DLL file and I had to go back to the manuals to figure it out again. Fortunately I already had the .DEF file but I used dumpbin /exports to verify the list of functions. The command to build the .LIB file was: lib /def:myfake.dll /machine:IX86 /verbose&lt;/p&gt;&lt;img alt="Command Prompt" src="http://static.flickr.com/1162/1453786443_b2af41bba0.jpg" border="0" /&gt;  &lt;p&gt;It didn't take too long to generate the .LIB file and compile and link the unit test. And sure enough I found the problem in a minute. Since the end use for the DLL is a simulation system, when the DLL makes function calls to methods involving time there is a callback function that allows the simulation to provide the time information. The language conversion utility is not aware of special system functions that need extra initialization (it was a feature I always wanted to add but never got time to do and I've moved on to other departments since then). It turned out the only thing missing was to add the TIMER structure to the function block structure in the C header file and everything was fine.&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:d8f9d159-2874-4d6d-8a0f-93d73c40f674" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati tags: &lt;a href="http://technorati.com/tags/command%20line" rel="tag"&gt;command line&lt;/a&gt;&lt;/div&gt;&lt;img src="http://nimblecoder.com/blog/aggbug/40.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Van Slooten</dc:creator>
            <guid>http://nimblecoder.com/blog/archive/2007/09/28/do-you-remember-all-of-your-command-line-parameters.aspx</guid>
            <pubDate>Fri, 28 Sep 2007 19:33:32 GMT</pubDate>
            <wfw:comment>http://nimblecoder.com/blog/comments/40.aspx</wfw:comment>
            <comments>http://nimblecoder.com/blog/archive/2007/09/28/do-you-remember-all-of-your-command-line-parameters.aspx#feedback</comments>
            <wfw:commentRss>http://nimblecoder.com/blog/comments/commentRss/40.aspx</wfw:commentRss>
            <trackback:ping>http://nimblecoder.com/blog/services/trackbacks/40.aspx</trackback:ping>
        </item>
        <item>
            <title>Death of single-threaded development?</title>
            <link>http://nimblecoder.com/blog/archive/2007/06/08/Death-of-single-threaded-development.aspx</link>
            <description>&lt;p&gt;I was reading my email when I came across this blog about the &lt;a href="http://blogs.zdnet.com/Ou/?p=519"&gt;death of single-threaded development&lt;/a&gt;. Now I've written many multi-threaded applications in C++ for applications, communications, and graphical displays, but I don't see the death of single-threaded development any time soon. I even wrote a paper while I was at university about how multi-threaded programming should be introduced in the curriculum much earlier. At the very least, the multi-threaded thought process should be taught but I don't see that happening.&lt;/p&gt; &lt;p&gt;Samples are usually distributed as single-threaded applications because they are easier to understand. Unfortunately people replicate the same style and methodology in their own applications. Until sample applications are distributed as multi-threaded applications, I do not believe single-threaded application will die or even that multi-threaded applications will outnumber single-threaded applications.&lt;/p&gt; &lt;h3&gt;My First "Real" (as in Commercial) Multi-Threaded Experience&lt;/h3&gt; &lt;p&gt;Personally, I'd love for more people to use multi-threading in applications. Unfortunately there is a significant learning curve where you progress from novice to expert. I remember one of my first multi-threaded applications involved reading communications data from a device asynchronously as the display updated the values. During QA, a bug was found if you clicked this dialog and pressed that button in just the right (or wrong) sequence you could crash the application. It turned out to be an issue where I forgot to suspend the communications thread before changing some key values. Actually, it wouldn't have crashed if there had been a semaphore in the communications thread to protect the resizing of an array.&lt;/p&gt; &lt;h3&gt;The Classic Case of Debugging Multi-Threaded Applications&lt;/h3&gt; &lt;p&gt;Another multi-threaded issue I had was a communications driver that has to run 24x7 on an embedded controller. There were four-&lt;em&gt;plus&lt;/em&gt; threads: one for the application, one to monitor and handle configuration changes, one for the TCP/IP source data, and one for each of the configured serial ports. The source data thread read data from the host and then allow the serial ports to read the data. During the update of the source data, I protected the data with a class modeled after the Delphi &lt;em&gt;TMultiReadExclusiveWriteSynchronizer&lt;/em&gt;. The application would mysteriously lock up after about 7 days and it was a particularly stubborn. Debugging crashes that occur only every 7 days takes a little while to find and fix. I suspected it was an issue with my scheduler (the component that controlled how quickly the threads execute or resume after completing an iteration). There was an issue with the scheduler early in the development where the tick counter could roll over (a &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/gettickcount.asp"&gt;DWORD holding milliseconds&lt;/a&gt; can count up to 49.7 days), but I knew that could be an issue from the beginning and fixed that quickly. After a good deal of debugging, I found the issue was with my &lt;em&gt;TMultiReadExclusiveWriteSynchronizer&lt;/em&gt; class. I wrote a stress test application which hammered the synchronizer and sure enough found the problem. The application is still in production and running in many different plants around the US.&lt;/p&gt; &lt;h3&gt;The Purpose or Need of Multi-Threading&lt;/h3&gt; &lt;p&gt;In the case of the &lt;a href="http://blogs.zdnet.com/Ou/?p=519"&gt;blog article&lt;/a&gt; mentioned at the beginning of this post, the author is promoting multi-threading for graphic and game algorithms but I believe it is broader than just graphic algorithms. I get frustrated when Outlook doesn't respond when it is downloading messages. Programming multi-threaded applications makes you a better programmer and a better debugger -- that is if you are successful at it. Some programmers are just not cut out for multi-threading applications.&lt;/p&gt; &lt;p&gt;Many web applications are moving to AJAX to provide a more seemless experience without a bunch of page loads. Unfortunately, some tasks still take a long time and should be handled differently. I modified a JobHandler (based on a &lt;a href="http://www.devx.com/asp/Article/29617"&gt;DevX article&lt;/a&gt;) to support long-running tasks (BizTalk orchestrations, web services, communications, etc.). I added an Abort function, a watchdog timer, and general information like start and finish time, Session ID, and user name. In web-based applications, usually you must poll the JobHandler to see if it is complete. In OS-based applications, you can use a notifier or callback function to avoid polling.&lt;/p&gt; &lt;p&gt;There are typically two reasons for multi-threading: to complete a task quicker and to provide a seemless response. The first reason is most compelling due to the enormous performance gains that can be achevied. It is also the more difficult case to design more since you have to divide the tasks or calculations across multiple threads. The second case usually doesn't increase performance significantly, but the user appreciates the application more when it isn't frozen and not updating. At least in this case, you can monitor the thread, provide feedback, and attempt to abort it if necessary.&lt;/p&gt; &lt;h3&gt;Common Issues with Multi-Threading&lt;/h3&gt; &lt;ol&gt; &lt;li&gt;Deadlocks -- classic issue, but also includes handling "hung" threads and using watchdog timers&lt;/li&gt; &lt;li&gt;Scheduling threads -- figuring out how to run the threads quickly or pause the threads without overloading the system&lt;/li&gt; &lt;li&gt;Notifications -- notifying the application or external systems about status or progress&lt;/li&gt;&lt;/ol&gt; &lt;h3&gt;Conclusion&lt;/h3&gt; &lt;p&gt;Multi-theading is broader than just game and graphics programming, although the need for multi-threading in those areas is significant and absolute. Multi-threading increases your ability and experience, although you must expect challenges along the way.&lt;/p&gt;&lt;img src="http://nimblecoder.com/blog/aggbug/28.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Van Slooten</dc:creator>
            <guid>http://nimblecoder.com/blog/archive/2007/06/08/Death-of-single-threaded-development.aspx</guid>
            <pubDate>Fri, 08 Jun 2007 16:08:01 GMT</pubDate>
            <wfw:comment>http://nimblecoder.com/blog/comments/28.aspx</wfw:comment>
            <comments>http://nimblecoder.com/blog/archive/2007/06/08/Death-of-single-threaded-development.aspx#feedback</comments>
            <wfw:commentRss>http://nimblecoder.com/blog/comments/commentRss/28.aspx</wfw:commentRss>
            <trackback:ping>http://nimblecoder.com/blog/services/trackbacks/28.aspx</trackback:ping>
        </item>
    </channel>
</rss>