🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #14907

Re: aborting a function

#14907
From: Yahia El-Qasem
Date: Sat, 26 Jul 2003 11:22
91 lines
3403 bytes
I do what you describe pretty often - with and without using threads...


- Setup a functor ( this is a C++ class encapsulating the logic of your
"talk_to_hardware" function which could take parameters and give results
back... ).

- Setup a "Stack" of functors

- Setup a Timer on your form

- In the OnClick handler of your Button just create a functor and add it to
the Stack

- In the Timer just execute the next pending functor from the stack

- To implement the abort logic just check for the boolean abort flag you
mention within the timer function
   when it is true you must signal this to the current functor ( i.e. by
calling some "abort" method of it ) and clear all
   elements of your stack...

- To prevent reentry just set a sentinel value on the entry of timer saying
"I am already executing..." and reset it at exit from Timer

- To abort just call as often as you can Application->ProcessMessages and
set the boolean abort flag accordingly...


HTH

Yahia


"Robert L. Smith" <bsmithOMIT@cinSPAMele.com> schrieb im Newsbeitrag
news:3f21a974@newsgroups.borland.com...
> I have a function which talks to some remote hardware through a serial
port:
>
>
>
> int talk_to_hardware(void)
>
>
>
> Because it uses the serial port, this function is not re-entrant.  It
takes
> anywhere from 10 msec to several seconds to execute.  Calling this
function
> from a ButtonClick event handler means a user can click faster than the
> function executes.  It is required that the extra overlapping calls be
> executed eventually and not simply discarded.
>
>
>
> There is also a requirement to add an abort function to terminate the
serial
> communication:
>
>
>
> void abort_talking(void)      // typically called from AbortButtonClick
>
>
>
> This should halt the currently executing talk_to_hardware and abort any
> pending calls.
>
>
>
> Is there a simple way to meet all these requirements?
>
>
>
> If abort_talking sets a global bool flag, then calling
> Application->ProcessMessages from inside talk_to_hardware can detect an
> AbortButtonClick but will also try to execute pending ButtonClicks.  More
> complicated approaches using threads and/or Windows messaging also haven't
> worked.  Any suggestions?
>
>
>
> Thanks in advance,
>
>
>
> Robert L. Smith
>
>
>
>
Technical Details
Message-ID: <3f2264f0@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!border3.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3f21a974@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,cb957e45a585bf2c
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-07-26 04:33:37 PST
Reply-To: "Yahia El-Qasem" <Yahia.El-Qasemno.spam@mgh.metro-ag.de>
From: "Yahia El-Qasem" <Yahia.El-Qasem@mgh.metro-ag.de>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3f21a974@newsgroups.borland.com>
Subject: Re: aborting a function
Date: Sat, 26 Jul 2003 13:22:54 +0200
Lines: 93
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 217.230.120.82
Message-ID: <3f2264f0@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1059218672 217.230.120.82 (26 Jul 2003 04:24:32 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!border3.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail