Understanding multithreaded applications in Delphi and Win32

Hi Guys,

I'm building a multi-threading framework in D2009 that will be generic, easy-to-use and abstracts away much of the ugly details of threads and plan on releasing it as an open-source package. 

The framework is not universal in the sense that it does not solve all multi-threading problems, rather it focuses on the reader/writer problem where you have several threads creating messages and several threads reading these messages. The framework contains a thread manager that orchestrates the work, a thread-safe multi-read queue (unlike TThreadList) and a garbagecollector that manages the destruction of processed messages. Reader threads can be of two kinds: round robin or sequential (and both can be
 running at the same time).

When using the framework, you concentrate on the definition of the message and a few other ancillary details such as what do you want the reader threads to do with the messages they are reading. You invoke the thread manager with the number of writer and reader threads and it takes care of the rest.

One issue I'm facing with this framework is this: the thread manager resumes the writer threads before the reader threads. All of these threads are given a tp_lower priority, yet the reader threads are starving; they don't seem to be able to access the queue of messages while the writer threads are busy churning messages like crazy. 

I know how to solve this problem (using a TEvent to let the writer threads wait until the number of non-processed messages drop beneath a certain threshold) so that's not the question. The question I'm struggling with is why do I need to arbitrate between a group of threads of the same priority contending for access to a critical section? Can I not expect Win32 to invoke the threads in a round-robin fashion (my assumption)? If the answer is 'yes' then there may be a flaw in the way the critical sections a
re protecting the message queue. If the answer is 'no' then how does Win32 implement threads? If so, is the Delphi implementation of threads in TThread wanting? 

I know this question is more architectural than technical in nature but I would greatly appreciate hearing from you guys before I fix this thing.

Thanks,

Naji.
0
Naji
2/20/2010 12:14:20 AM
embarcadero.delphi.win32 2183 articles. 0 followers. Follow

1 Replies
539 Views

Similar Articles

[PageSpeed] 25

Naji Mouawad wrote:

> ...
> 
> One issue I'm facing with this framework is this: the thread manager
> resumes the writer threads before the reader threads. All of these
> threads are given a tp_lower priority, yet the reader threads are
> starving; they don't seem to be able to access the queue of messages
> while the writer threads are busy churning messages like crazy.
> 
> ...

You can use my queue either as a concept or as a completed unit. BSD
license, which means you are free to do anything short of naming
yourself as the author of that unit.

http://17slon.com/blogs/gabr/2010/02/dynamic-lock-free-queue-doing-it-right.html

In this implementation, readers are completely decoupled from writers
and ones don't block the others.

---
Primoz
0
Primoz
2/20/2010 9:03:11 AM
Reply:

Similar Artilces:

delphi Win32 using delphi .NET dll
Hi, I'm trying to use a delphi.NET dll in delphi.WIN32. I am currently using CodeGear Delphi 2007 with version2(base version) of .NET I can get the dll to import into the WIN32 application the only problem is when i include things such as: "using Classes,DateUtils, SysUtils" in the .NET dll the win32 application will instantly hang when any of the dll functions are called. Any help would be great thanks. Also I have tried this example and it also crashes for me? http://cc.embarcadero.com/Item/22688 -Braden I also found this.. "The problem is that, wehn you instal...

Delphi.NET loading Delphi.Win32 Driver
Hi, What I'm trying to do is marshal an array of cardinal (or integer) back into managed memory from a win32 dll. I know how to pass managed memory into a win32 dll {code} var aa : array of Integer; Buffer : IntPtr; begin SetLength(aa,2); aa[0] := 1; aa[1] := 80; if not Supports(ExtractFilePath(Application.ExeName)+'Win32_Library\SDK_Driver.Win32.io', TypeOf(IMyFunctions), MyFunctions) then Exit; //loads the driver into memory. MyFunctions contains the method names found in the SDK_Driver. Buffer := Marshal.AllocHGlobal(2 * {Marshal.SystemDefaultC...

Converting Delphi for Win32 to Delphi .Net(Prism)
Hi, I am currently migrating a project from Delphi for Win32 to Delphi.net. Part of my code currently goes into a directory and pulls out a random file from this directory and loads the contents of the file for me. This code doesn't seem to work in Delphi.Net. It uses PString and a number of functions in SysUtils that don't seem to be present in Delphi.net's SysUtils file. If anyone can help me please, it would be greatly appreciated! Many thanks, Jonathan Mackey Jonathan Mackey a écrit : > I am currently migrating a project from Delphi for Win32 to &...

Migrate from Delphi 2007 for Win32 to Delphi XE
we use Delphi 2007 for Win32 to support legacy (32Bit) OWL-based pascal applications (yes i know it was a mistake not to switch to VCL 15 years ago). could our applications still be opened and compiled with Delphi XE? The existing projects are all plain Pascal-Code, coming back from the times of Turbo Pascal for Windows and later on Borland Pascal. Are there any improvements we could profit from (i.e IDE, Debugger)? Thanks Andrej > {quote:title=Andrej Dimic wrote:}{quote} > could our applications still be opened and compiled with Delphi XE? I'm not sure, but I guess ...

Delphi Win32 applications on iPad?
Hello, I'm not even sure if this is possible but I thought i would ask anyway. I have developed a native Win32 application that runs in Windows using Delphi 2006 and I have been asked by my company to see about the possibility for the application to run on Apple iPad's. Can anyone offer any advice or point me in a direction? From a quick google search the Delphi Prism XE IDE came up quite alot? can Delphi Prism XE open up and port my win32 code? Chris > > Can anyone offer any advice or point me in a direction? From a quick google search the Delphi Prism XE IDE ca...

Win32 program: Delphi 7 vs Delphi XE5
How is a D7 Win32 program compared to a Delphi XE5 one in terms of stability and performance? Is Delphi XE5 good enough for a big ERP project with several DLL's and hundreds of units and forms? Thanks in advance Am 26.12.2013 15:02, schrieb lior ilan: > How is a D7 Win32 program compared to a Delphi XE5 one in terms of stability > and performance? > Is Delphi XE5 good enough for a big ERP project with several DLL's and > hundreds of units and forms? > Thanks in advance > Hello, XE5 has increased functionality. Stability seems to be ok for most ...

Win32 Delphi language features introduced since Delphi 7
Hi, Am I right in thinking that the language features introduced since Delphi 7 fall into the categories: a) language features dictated by .Net compatibility. e.g. Namespaces, Inlining, records with methods, operator overloading, pure interfaces, generics, extended RTTI and reflection; b) Unicode strings and supporting procedures? c) 64-bit support What other language features, if any, have been introduced since D7? Had most of the post-D7 languages features, except for generics, Unicode strings, and 64-bit support, been introduced in or before Delphi 2005? How bug-free were ...

How to detect if my Delphi Win32 application has been installed by Setup ?
Hi, What I would like to know is how can I detect if my delphi application Win32 (from this EXE) has benn installed by a Setup.exe or .MSI ? How can I retrieve the list of applications installed under the current windows version (from XP and Vista too) ? Thank you for any suggestion or link or whatever... Regards, Laurent laurent pierre wrote: > How can I retrieve the list of applications installed under the current windows version (from XP and Vista too) ? HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall ...

How to import *.jar to Win32 Application (Delphi 7) [Edit]
Hi all. Please I need help. I need some way to call *.jar from Win32 application to use its methods. This jar working in a following way: I should push as parameter xml file and jar program will return pdf file. Previously I was using ShellExecute to pass xml as parameter, xml was small. But I hit problem - error 'input line is to long'. Basically xml now to big - error caused by Windows command line limit. I started realizing that I need some way to import jar as class to my project like I can do with Ac tiveX or some way convert jar to dll. I have seen in internet JNI project where ...

[PATCH] Move Win32 from win32/ext/Win32 to ext/Win32
To compile the Win32 module under both "MSWin32" and "cygwin" the module needs to be moved to the ext/ subdirectory. To preserve the change history this should be done with `p4 integrate`: p4 integrate win32/ext/Win32/... ext/Win32/... p4 delete win32/ext/Win32/... The attached patch then updates Configure to build the module under cygwin only, and updates the MANIFEST. The MSWin32 builds will continue to find the module automatically using the FindExt.pm module. Cheers, -Jan diff -dur bleadperl/Configure bleadnew/Configure --- bleadperl/Conf...

Creating web-applications for iPhone, iPad and Android using Delphi Win32
Raudus is a web-framework and control set for Delphi. Recently a new version of Raudus was released. Now you can create web-applications for mobile devices (iPhone, iPad, Android-based) using Delphi Win32. Just have a look at video: http://www.raudus.com/demos/ Please give your feedback. Thank you! Igor Klopov > {quote:title=Igor Klopov wrote:}{quote} > Raudus is a web-framework and control set for Delphi. > Recently a new version of Raudus was released. > Now you can create web-applications for mobile devices > (iPhone, iPad, Android-based) using Delphi Win32. ...

Lost VCL Forms Application
As per the subject I've managed to lose the VCL Forms Application from the New Menu in codegear rad studio 2007. Also I can't view any of the forms on my current projects. Before anyone asks yes I've looked under customise as I'm aware you can add/remove items and it's not under there either. I've tried running a repair from the original files but to no effect. Are there anything to check/replace before I delete the installation and start from scratch? Thanks Paul ...

re: [PATCH] Move Win32::* functions from win32/win32.c to ext/Win32/Win32.xs
----=_e3pon25ktlh8mqd3tgjj1tt7en166ucrfq.MFSBCHJLHS Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit > patch2.diff moves the Win32::* functions into the ext/Win32 module and > adds forwarder functions to load the module at runtime on first use: > > static void > forward(pTHX_ const char *function) > { > dXSARGS; > Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT, newSVpvn("Win32",5), NULL); > PUSHMARK(SP-items); > call_pv(function, GIMME_V); > } It just occurred to me that Perl_load_modul...

Delphi (Win32)
Hi all, I am looking for a Delphi/Win32 equivalent of the .Net SqlBulkCopy class... is there something available? Background: I want to load CSV/Text files directly into a DB table. Files have various formats, e.g. field separator, text delimiter etc. TIA, Levend. > Background: I want to load CSV/Text files directly into a DB table. Files have various formats, e.g. field separator, text delimiter etc. What database are you using ? Hi Robert, I am mainly using MS SQL Server. Thus a 1:1 equivalent of .Net SqlBulkCopy is what I am looking for - although I would not complain...

Web resources about - Understanding multithreaded applications in Delphi and Win32 - embarcadero.delphi.win32

Trump Calls Saudi Prince 'Dopey'
Daily Beast Trump Calls Saudi Prince 'Dopey' Daily Beast Republican presidential hopeful Donald Trump is in yet another Twitter fight, this ...

See aerial images of climate activists doing funky things in Paris
On Saturday, as U.N. climate negotiations plodded toward a finish, Friends of the Earth International staged a geolocation action. Its activists ...

The Latest: California Shooting Victim Mourned
The Latest: Man who shielded co-worker during California shooting is mourned

The batter is strong with these 'Star Wars' themed pancakes
You should feel bad about burning your frozen waffles beyond recognition this morning. Youtube user Dancakes is back with another crazy detailed ...

Barack Obama: Discrimination Against Muslims In The United States Only Strengthens ISIS
President Barack Obama is taking a stand for Muslims, warning Americans that stereotyping all Muslim people based on the actions of violent extremists ...

Police: Teen who pointed BB gun at officer shot in leg
NBCNews.com Police: Teen who pointed BB gun at officer shot in leg seattlepi.com JACKSONVILLE, Fla. (AP) — A black teenager carrying a BB ...

Elon Musk Backs $1 Billion Artificial Intelligence Research Group
Elon Musk and other technology giants have chipped in $1 billion toward researching artificial intelligence to “benefit humanity,” the business ...

Here's how the top iPhone apps are using 3D Touch
When Apple introduced 3D Touch on the iPhone 6S this September, it described the technology as a revolutionary paradigm for interacting with ...

Banksy draws attention to refugee crisis with Steve Jobs mural - Videos - CBS News
Street artist Banksy is weighing in on the Syrian refugee crisis with a series of murals in the French port of Calais, including an image of ...

Saudi Arabia: Voting begins as women stand as candidates in elections for the first time
A total of 978 women registered as electoral candidates, along with 5,938 men.

Resources last updated: 12/12/2015 5:29:50 PM