Hi Benito,

Making a multi-threaded anything tends to be harder than it at first
seems... at least to get it purring flawlessly. Each language etc has
it's own quirks etc. Pascal, FreePASCAL is no exception.

For starters - are you 100% positive there is no contention with
variables shared by the threads? Perhaps unknowningly? Are you sure the
entire lineage of code you are calling in Synapse and in FreePascal's
supplied units (FCL/RTL) and lazarus components are NOT stomping each
other? 

Have you taken measures to address FreePascal's GLOBAL FileMode variable
when opening/reading/writing files in a multi-threaded setting?

The itch of it all is that the threads will die in what appears to be in
a completely random way - making solving these issues difficult.

what I've done (Going the other way - a multi-threaded application/web
server) is make sure I have a thread safe mechanism from the very ground
up that allows me to record each thread individually - where it goes,
when it comes back etc. I do this with a separate log file per thread
and I use the memory address (typecasted) to make up part of the file
name. You need to address the filemode variable I mentioned above to get
this in place. 


I made a wrapper thread class around the Freepascal TThread class, that
has a variable named iNestLevel: integer; I have a function called DBIN
and a mate to it DBOUT. Each routine looks something like:

//=============================================================================
procedure TJThread.OnMessage;
//=============================================================================
begin
  {$IFDEF DBINDBOUT}
  DBIN(201002031619,'TJThread.OnMessage',SOURCEFILE);
  {$ENDIF}
  
  Your Code here

  {$IFDEF DBINDBOUT}
  DBOUT(201002041114,'TJThread.OnMessage',SOURCEFILE);
  {$ENDIF}
end;
//=============================================================================

The funky codes that are YYYYMMDDHHnn are so I can search my source code
for the 
last entry in the log before the thread died or whatever.. got sck..etc.
The conditionals are so I can exclude the code for final releases.

The output of these functions looks like this... just an excerpt.. (TURN
off word wrap or this will look VERY BAD)

BEGIN-----------------THREAD LOG FILE SNIPPET
BEGIN-----------------THREAD LOG FILE SNIPPET
BEGIN-----------------THREAD LOG FILE SNIPPET
201002030013  -   --->> |TWORKER.ExecuteMyThread
---------------------------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030014  -   --->> |.TWORKER.ExecuteMyThread - Part #1
-----------------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030014  <<---   - |.TWORKER.ExecuteMyThread - Part #1
-----------------------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030015  -   --->> |.TWORKER.ExecuteMyThread - Part #2
-----------------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030042  -   --->> |..TWORKER.iParseRequest
-----------------------------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030042  <<---   - |..TWORKER.iParseRequest
-----------------------------------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030015  <<---   - |.TWORKER.ExecuteMyThread - Part #2
-----------------------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030016  -   --->> |.TWORKER.ExecuteMyThread - Part #2.5 Wedge
---------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030016  <<---   - |.TWORKER.ExecuteMyThread - Part #2.5 Wedge
---------------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030017  -   --->> |.TWORKER.ExecuteMyThread - Part #3
-----------------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030017  <<---   - |.TWORKER.ExecuteMyThread - Part #3
-----------------------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030018  -   --->> |.TWORKER.ExecuteMyThread - Part #4
-----------------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030018  <<---   - |.TWORKER.ExecuteMyThread - Part #4
-----------------------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030019  -   --->> |.TWORKER.ExecuteMyThread - Part #5
-----------------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030019  <<---   - |.TWORKER.ExecuteMyThread - Part #5
-----------------------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030021  -   --->> |.TWORKER.ExecuteMyThread - Part #6
-----------------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030021  <<---   - |.TWORKER.ExecuteMyThread - Part #6
-----------------------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030023  -   --->> |.TWORKER.ExecuteMyThread - Part #7
-----------------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030023  <<---   - |.TWORKER.ExecuteMyThread - Part #7
-----------------------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030024  -   --->> |.TWORKER.ExecuteMyThread - Part #8
-----------------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030024  <<---   - |.TWORKER.ExecuteMyThread - Part #8
-----------------------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030025  -   --->> |.TWORKER.ExecuteMyThread - Part #9
-----------------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030033  -   --->> |..TWORKER.ExecuteMyThread - Part #9 - calling
getfile
-----------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030008  -   --->> |...TWORKER.getfile
-----------------------------------------------------------------------------------------------------------------
Begin u01j_api.pp
201002030008  <<---   - |...TWORKER.getfile
-----------------------------------------------------------------------------------------------------------------
End   u01j_api.pp
201002030033  <<---   - |..TWORKER.ExecuteMyThread - Part #9 - calling
getfile
-----------------------------------------------------------------------------
End   u01j_jcore.pp
201002030025  <<---   - |.TWORKER.ExecuteMyThread - Part #9
-----------------------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030034  -   --->> |.TWORKER.ExecuteMyThread - Part #9.5
---------------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030034  <<---   - |.TWORKER.ExecuteMyThread - Part #9.5
---------------------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030035  -   --->> |.TWORKER.ExecuteMyThread - Part #10
----------------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030035  <<---   - |.TWORKER.ExecuteMyThread - Part #10
----------------------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030036  -   --->> |.TWORKER.ExecuteMyThread - SNR Header Content
Length
-----------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030036  <<---   - |.TWORKER.ExecuteMyThread - SNR Header Content
Length
-----------------------------------------------------------------------------
End   u01j_jcore.pp
201002030037  -   --->> |.TWORKER.ExecuteMyThread - Send out the Headers
----------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030037  <<---   - |.TWORKER.ExecuteMyThread - Send out the Headers
----------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030038  -   --->> |.TWORKER.ExecuteMyThread - Sending Payload
---------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030038  <<---   - |.TWORKER.ExecuteMyThread - Sending Payload
---------------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030039  -   --->> |.TWORKER.ExecuteMyThread - Closing Socket
----------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030039  <<---   - |.TWORKER.ExecuteMyThread - Closing Socket
----------------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030040  -   --->> |.TWORKER.ExecuteMyThread - DIAGNOSTIC_LOG
----------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030040  <<---   - |.TWORKER.ExecuteMyThread - DIAGNOSTIC_LOG
----------------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030041  -   --->> |.TWORKER.ExecuteMyThread - LOG FILE PROCESSING
-----------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030041  <<---   - |.TWORKER.ExecuteMyThread - LOG FILE PROCESSING
-----------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030013  <<---   - |TWORKER.ExecuteMyThread
---------------------------------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030013  -   --->> |TWORKER.ResetThread
-------------------------------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002031627  -   --->> |.TJThread.ResetThread
------------------------------------------------------------------------------------------------------------
Begin u01g_jfc_threadmgr.pp
201002031627  <<---   - |.TJThread.ResetThread
------------------------------------------------------------------------------------------------------------
End   u01g_jfc_threadmgr.pp
201002030013  <<---   - |TWORKER.ResetThread
-------------------------------------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030013  -   --->> |TWORKER.ExecuteMyThread
---------------------------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030014  -   --->> |.TWORKER.ExecuteMyThread - Part #1
-----------------------------------------------------------------------------------------------
Begin u01j_jcore.pp
201002030014  <<---   - |.TWORKER.ExecuteMyThread - Part #1
-----------------------------------------------------------------------------------------------
End   u01j_jcore.pp
201002030015  -   --->> |.TWORKER.ExecuteMyThread - Part #2
-----------------------------------------------------------------------------------------------
Begin u01j_jcore.pp

END-------------------THREAD LOG FILE SNIPPET
END-------------------THREAD LOG FILE SNIPPET
END-------------------THREAD LOG FILE SNIPPET


I hope this helps you out.

--Jason



-------- Original Message --------
Subject: [Synalist] THttpSend and multi threading
From: Benito van der Zander <[email protected]>
Date: Thu, February 04, 2010 2:49 pm
To: [email protected]

Hi,
I start simultaneously several TThreads which use THttpSend to connect 
to several sites.
However, in around 20% of the threads this connection fails randomly. 
(httpmethod returns false and it always happens with different threads)
Has anyone idea how to solve this problem? (the environment is fpc 
2.2.4, latest Lazarus and debian squeeze)


Regards,
Benito van der Zander



------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the
business
Choose flexible plans and management services without long-term
contracts
Personal 24x7 support from experience hosting pros just a phone call
away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
synalist-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synalist-public


------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
synalist-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synalist-public

Reply via email to