Article View: borland.public.cppbuilder.nativeapi
Article #346Re: Moving hooke callback to thread - suggestions? (was:Hooks, once again)
From: Anders Johansen
Date: Thu, 08 May 2008 09:32
Date: Thu, 08 May 2008 09:32
29 lines
2169 bytes
2169 bytes
Bob Gonder <notbg@notmindspring.invalid> wrote:
>Anders Johansen wrote:
>
>>The code below has a potential flaw: The callback code is
>>running in the main thread, and so may block the system event
>>processing or at least delay it.
>
>The only slow part in the hooks I can see is notifyKeyDown,
>and it's reliance on virtual KeyDown functions.
>Everything else should be quite fast enough.
Good suggestions!
The problem is however that if you include this code in a program that blocks the message processing loop (say, by doing while (true) {};) the system temporarily becomes unresponsive, as the callbacks are blocked from executing for some reason. This happens even if no observers are registered. This is why I expect that moving the event processing etc. to another thread is a Good Idea.
Of course, this introduces a risk that the event handlers could be run outside the main thread, which would create problems with VCL code I expect.
Therefore my idea is:
* Place Hook code in separate thread
* Convert events to window messages sent asynchronously to the main thread (or some other way to avoid threading issues in VCL).
Anders
A
Technical Details
Message-ID:
<4822c89f$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!news.isoc.lu!newsgroups.borland.com!not-for-mailReferences:
<47c935cb$1@newsgroups.borland.com> <48217905$1@newsgroups.borland.com> <24c3249pbvhtdcpjihmskrvr9pisljt7g6@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,4ebd883022a89a5d X-Google-Attributes: gid10cc67,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Anders Johansen" <home@dduck.dk> Sender: "Anders Johansen" <home@dduck.dk> Reply-To: "Anders Johansen" <home@dduck.dk> Subject: Re: Moving hooke callback to thread - suggestions? (was:Hooks, once again) Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 130.226.221.25 References: <47c935cb$1@newsgroups.borland.com> <48217905$1@newsgroups.borland.com> <24c3249pbvhtdcpjihmskrvr9pisljt7g6@4ax.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <4822c89f$1@newsgroups.borland.com> Date: 8 May 2008 02:32:15 -0700 X-Trace: newsgroups.borland.com 1210239135 207.105.83.66 (8 May 2008 02:32:15 -0700) Lines: 29 Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!news.isoc.lu!newsgroups.borland.com!not-for-mail