Forum > Networking and Web Programming

Threads and Synapse

(1/1)

flasher86:
Hi. I am beginner at working with threads but I think it's time to work it out.

I am writing database software which communicates with online database services and downloads prices and availability of many different goods. I am using THTTPSend to achieve that, but when It connects to the server my application hangs in couple of occasions (when waiting for server response, and converting received data into my local format).

To communicate I created a complete class which is using Synapse and many other libraries.

How to put this class in another thread so the main thread won't hang during communication with other servers.

I tried to start working with this but it didn't work - the main thread locked up as usual when waiting for server response.

Dibo:
Hi,

There is very nice tutorial about threads in lazarus:
http://wiki.lazarus.freepascal.org/Multithreaded_Application_Tutorial

I used threads + synapse for a long time. But I always had a problem with the immediate and safe termination of threads. On synapse mailing list, I get some tricks about aborting threaded synapse from main thread, but often and randomly, I received SIGSEGV errors doing that. So I found this sockets:
http://wiki.lazarus.freepascal.org/lNet
And all my problems are gone. lNET are non-blocking sockets, so I don't have to use threads but you'll need to change the logic of your program (see demos)

garlar27:
Hi,
   We are using TTCPBlockSocket in threads + TZConnection (ZEOS) and we never have had the problems posted by Dibo.

   The only tip I can give you is: Under no circumstances allocate memory (Create object or instantiate Pointers) within the TThread.Execute method because if the thread has a sudden death you'll have a memory leak. Its better allocate memory in the Constructor and dispose it in the destructor.

alivardar:
Hi,

I used thread and synapse in that project. You can download source code. It is GPL application.

http://www.turbog.com/index.php?page=17

M.Ali VARDAR

Navigation

[0] Message Index

Go to full version