[fpc-devel] Strange behaviour with Synapse
Ludo Brands
ludo.brands at free.fr
Sat Mar 16 18:25:20 CET 2013
On 03/16/2013 03:48 PM, Geoffray Levasseur-Brandin wrote:
> I'm mailing you as I have a very strange behaviour of a program
> I'm
making
> using FPC 2.6.2 and Lazarus from trunk (updated this morning). As
far as I
> know it's either a compiler bug or a Synapse bug.
That is always a dangerous assumption;)
>
> Thank you for any help !
>
There is quite more needed to get the code running. I can't get it
compiled on my kubuntu 12.04. It complains about duplicate resources.
Anyways, looking at the code, you create a thread TDownloadListLoop
that loops over the files to download. The download is done in another
thread TDownloadDaemon created in TDownloadListLoop.Execute with
PDownloader^.StartDownload. TDownloadListLoop.Execute then loops until
PDownloader^.State = drDone. Now, in TDownloader.HTTPComplete, called
from TDownloadDaemon.Execute with a synchronize you do
FState := drDone followed by FDownloadFeedback(FResponse) and a
FHttp.Clear. Chances are that TDownloadListLoop.Execute continues and
starts a download of the next file before TDownloader.HTTPComplete
does the FHttp.Clear. PDownloader^.State = drDone is too early.
Buy the way, you didn't mention if you encountered the problem with
http or ftp. So above is just speculation. One of the places where it
can go wrong.
In any case I don't understand your architecture. Why using a thread
for the loop, do a HEAD in the same thread and then create another
thread to do the GET? If you only do one download at a time why the
2nd thread TDownloadDaemon? On top of that your code becomes overly
complex because methods in TDownloader are called in the context of
the TDownloadListLoop thread and of the main thread (synchronize from
TDownloadDaemon). A good recipe for race conditions and unreproducible
errors.
Ludo
More information about the fpc-devel
mailing list