🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pascal.delphi.databases
Article #74

Background thread writing to DB - dealing with app shutdown

#74
From: Chris Moseley
Date: Wed, 13 Jan 1999 00:00
34 lines
2023 bytes
Hi all. 

I have a background thread writing a (selective) log of user 
activity to a table for audit purposes. On occasion this will
receive a significant number of entries just before the app 
terminates (the user goes "yup, save all of those, I'm done").

At this stage the UserLog unit creates/starts and frees the
thread in the initialization/finalization sections, but
this causes AV's if the thread is active when the app 
terminates - it looks as if the memory used is free'd from 
underneath the thread.

Questions:
1: does code in the finalization block actually have to
   complete before the app shuts down? I've assumed so.
2: It looks as if the app does not wait for my thread to 
   terminate. Correct?

What's the best way around this?
- terminate the thread then write any remaining entries from
  the main thread.
- do that but using the database and query owned by the thread
- sit in a loop polling the buffer until it's empty, then 
  exit the finalization block?
- do something else. Any ideas?

The other thing I've thought of doing in making the thread 
depend on the main form - put the start/stop into the form
create/free. Does this sound reasonable?

Thanks
Moz
Technical Details
Message-ID: <369BBB1F.A581D919@acs.co.nz>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: ff75c,20a07d8886a0460
X-Google-Attributes: gidff75c,public
X-Google-Thread: ffff5,20a07d8886a0460
X-Google-Attributes: gidffff5,public
From: Chris Moseley <moz@acs.co.nz>
Subject: Background thread writing to DB - dealing with app shutdown
Date: 1999/01/13
Message-ID: <369BBB1F.A581D919@acs.co.nz>
X-Deja-AN: 431873795
Cache-Post-Path: news.iconz.co.nz!unknown@acs.internet.co.nz
Content-Transfer-Encoding: 7bit
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: newsabuse@remarQ.com
X-Trace: 916175224 KNNGTFYPT6401CAE C usenet80.supernews.com
Organization: Alpha Centauri Systems Ltd
Mime-Version: 1.0
Newsgroups: comp.lang.pascal.delphi.databases,borland.public.delphi.database.desktop