Author Topic: Threads and Synapse  (Read 8057 times)


  • New Member
  • *
  • Posts: 15
Threads and Synapse
« on: December 18, 2010, 12:48:53 pm »
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.


  • Hero Member
  • *****
  • Posts: 1048
Re: Threads and Synapse
« Reply #1 on: December 18, 2010, 06:32:01 pm »

There is very nice tutorial about threads in lazarus:

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:
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)


  • Hero Member
  • *****
  • Posts: 652
Re: Threads and Synapse
« Reply #2 on: January 03, 2011, 09:58:25 pm »
   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.


  • Newbie
  • Posts: 4
Re: Threads and Synapse
« Reply #3 on: January 19, 2011, 01:58:47 pm »

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



TinyPortal © 2005-2018