Monday, June 30, 2008

OmniThreadLibrary - threading library for Delphi [WIP]

imageIn my $$$ line of programming, everything revolves around threads. Servers, multithreaded processing on clients, real time hardware control ... you name it. In all the years I've learned many dos and don'ts of multithreaded programming. I've also written few frameworks to simplify this job and most of them are already retired. Sometimes a potentially good approach turns out not to be so good at all ...

In the last year I've become more and more unhappy with my current framework and decided that it's time for something better, something simpler. Something built from scratch. This time I didn't start with the implementation but tried to visualize how I'd like to use my framework in real-life applications. After all, I had all those test cases lying around in form of my old applications using old framework. And so, the OmniThreadLibrary was born.

Currently OTL is in a very fluent alpha state. I'm already using it in my projects but some more important interfaces are changing from day to day. Still, you're invited to try it and to comment on its usefulness. If you can give me an example of real-world problem that can't be implemented using OTL, all the better. Maybe I'll be able to enhance the OTL to suite your purpose more.

OTL is living on the Google Code hosting and is BSD licensed. Current implementation only supports Delphi 2007 (although I'd been told that only small modifications are required to make it work with Delphi 2006) and unless I'm given a very convicting business case support for older Delphis won't be included. Let's look into future, not into past.

Some examples are included in the repository, but not all parts of the current infrastructure are explored. I'll post more on OTL and describe examples and OTL's inner workings on this blog in the next few days.

Labels: , , , , , ,


Anonymous ramos said...


I really like your library as it is helping me understand and use threads. Just a question as I am a beginner: how can I use your library for a download manager?

Blogger gabr said...

If you're using ICS for TCP/IP work then you have no reasons to use threads at all.

If you're using Indy or something else, I have no idea. I'm using ICS for all my internet needs.

Anonymous ramos said...

I use synapse - similar to Indy.

thanks for your help anyway.


Blogger gabr said...

If I understand Indy correctly, you have to start separate thread for each request. Is this the same with Synapse?

In most cases you'd want to use the approach from Example #4a (or from Example 4, but as you're a beginner, you'd probably want to keep away from interfaces). I'm guessing that each download task would need a .MsgWait decorator, too.

Still, all that is just a guess - if anybody here knows the Synapse, please leave a more useful comment.

Anonymous Anonymous said...

No - Synapse uses blocking sockets, there is no async or threading support (the upside being the library's elegance and simplicity), which is probably why ramos wanted to use threads.

Blogger gabr said...

In that case, it's really simple.

Create a task and send it URL to download. In the task code, download the URL with Synapse. Send a message back to the owner (Task.Comm.Send()) when URL is downloaded.

As for the pausing of downloads, cancellation and other important parts of the download manager - I have no idea as I don't know how Synapse works.

Anonymous Anonymous said...

Do you happen to know what small modifications need to be made to the code for it to work in Delphi 2006?

Blogger gabr said...

I believe it had to do with record constructors.

Still, that was many versions ago. I have no idea if the code can be made working in Delphi 2006 at this time.

Anonymous Anonymous said...

Delphi 7 is not supported because there is no reason?
Have a look at this survey:

Blogger gabr said...

There is no reason *for*me* to support Delphi 7. I'm not using D7 anymore and neither are my clients. The last one switched to D2007 few months ago.

If a company somewhere out there had a strong business case to use the OTL in an older Delphi, they can outsorse the conversion project to me, of course.

If anybody else wants to modify the OTL to work with D7, I'll included modified version in the SVN. I won't actively support it, though. D7 is history, people, face it.


Post a Comment

Links to this post:

Create a Link

<< Home