Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TThread - Delphi 4

0 views
Skip to first unread message

Philip B Cook

unread,
Aug 19, 2000, 3:00:00 AM8/19/00
to
I am using a TThread descendant to carry out a file copy process, so that my
main program can continue to receive and process timer messages that update
a window displaying the progress of the copy.

For each file I copy I am creating and then freeing a TThread object.

My problem is that after around 30 files, the next thread creation never
starts execution of the copy code.

Any ideas, or examples of how this should be done ?

Philip

Philip B Cook

unread,
Aug 19, 2000, 3:00:00 AM8/19/00
to
Apologies everyone. The problem was me failing to detect a timing glitch
when the thread starts up when copying very small files. I have fixed it
now. Plase delete the question.

Philip

Philip B Cook <phili...@smoogro.freeserve.co.uk> wrote in message
news:399e6360_1@dnews...

Peter Below (TeamB)

unread,
Aug 19, 2000, 3:00:00 AM8/19/00
to
In article <399e6360_1@dnews>, Philip B Cook wrote:
> I am using a TThread descendant to carry out a file copy process, so that my
> main program can continue to receive and process timer messages that update
> a window displaying the progress of the copy.
>
> For each file I copy I am creating and then freeing a TThread object.

Bad approach, in my opinion. You should have a single thread and a queue of
copy requests it works on (a TThreadlist of task objects, for instance). If
you create a thread for each copy operation you end up with several running in
parallel. Since the actual disk access has to be serialized by the OS anyway
you will rapidly reach a point where adding more threads makes the overall
process slower, due to the management overhead of threads. If you run on
Win9x, for example, a process should not create more than 16 threads and even
that only if most of them will be blocked most of the time.

Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!


Werner Lehmann

unread,
Aug 19, 2000, 3:00:00 AM8/19/00
to
Philip B Cook wrote:
>
> Any ideas, or examples of how this should be done ?

Philip,

I have no idea on what your problem might be. Some error in the
code probably. But I think you can do the same without threads.
Just recently I had a complex 4 thread design which ended in a
deadlock after several minutes of processing. Took me days to
develop this. Only to discover that it runs just fine without
any additional threads.

Have developed a class that can move files, folders and whole
directory trees (TFileOperation). The copy operations still have
to be added but since I don't use them yet... You get an event
before and after each file or folder is moved and an additional
event if an error occurred with information why this did not work.

All without threads. Contact me if you want to know more.

Or you simply use ShFileOperation and you get the windows copy/
move window with flying files and windows worries about every-
thing (I needed more details so this was not for me).

Regards,
WL


Martin Harvey

unread,
Aug 19, 2000, 3:00:00 AM8/19/00
to
Philip B Cook wrote:
>
> Apologies everyone. The problem was me failing to detect a timing glitch
> when the thread starts up when copying very small files. I have fixed it
> now. Plase delete the question.

Ahha... that bugbear of stread writers: the timing window.

<blatant plug> Why not refresh your mind with a copy of

http://www.pergolesi.demon.co.uk/prog/threads/ToC.html
</blatant plug>

There's a demo in there that calculates CRC's for a directory which
might be of interest.

MCH.

--
Martin Harvey. mar...@pergolesi.demon.co.uk
http://www.pergolesi.demon.co.uk
ICQ: 37298917

0 new messages