Le dimanche 17 mars 2013 09:05:45 Ludo Brands a écrit : > Also, get rid of all these synchronizes. When using multiple threads, > you will be blocking your downloads too much. Every sock status change, > you create a string for the GUI, synchronize to update the screen, call > Application.Processmessages to make sure the GUI gets updated. That is a > huge waste of resources and slows down downloads considerably. On top of > that you have timers that also update the GUI. > Turn this around. Have TDownloadDaemon do the complete download and > nothing else. Put status in properties of TDownloadDaemon, using a > critical section if you want to pass strings, and poll your download > threads in the main thread to update the GUI. You have already a timer. > Make it faster (fe. 200ms) and update your GUI from there. Nobody will > see the difference. No more synchronize and Application.Processmessages > anymore and your program flow becomes so much easier. Multi-threading is > difficult and simplifying your program flow is key to getting it right. > > I changed the project to GTK2 and got it running. It crashes not always > at the same time but it is systematically in the synchronize in > TDownloadDaemon.SockStatus and always when doing the HEAD. So that is a > synchronize called inside a synchronize from the TDownloadListLoop. You > should not call synchronize from the main loop. Worse, > TDownloadDaemon.SockStatus calls Synchronize(FOnProgress) which calls > TThread.Synchronize(self,AMethod). Self is TDownloadDaemon but since you > call TDownloadDaemon.SockStatus here from the main thread, synchronize > uses the wrong AThread. The first download it happens to work because > there is no thread running when you do HEAD. The second time you aren't > that lucky. In any case, this is an overly complex program flow and is > simply asking for problems. > > Ludo
Thank you for all the advices. I just removed TDownloadDeamon thread to merge it with TDownloader. And it works ! I still have to work on status/progress system which is a bit messy. If you are interested, I've just commited the changes in the svn repo. Thank you again, -- Geoffray Levasseur-Brandin <geoffray.levasseur-bran...@ac-toulouse.fr> http://jeff.levasseur.tuxfamily.org/ GNU/PG : BF8BB8407CD26E89466CDA9BB1030FC59EF87775 Errare humanum est sed perseverare diabolicum aut cretinum.
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel