[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

DELPHI APPLICATION HANGS AFTER 80 HOURS MULTITHREAD ADVICE HOW TO SOLVE SEARCH??

Asked by TDDatATS in Delphi Programming

Tags: delphi

Hi there,

our company has written an application which has a connection with another application.
This application is a TCP client program that sends TCP commands to our program.
Our program interpretes these commands and generates pulses. When these pulses are generated, an ARCNET network is scanned to see if someone interrupts this pulse. This sequence is done app. every 5 seconds. When the ARCNET message comes in, the application stops generating pulses, sends out some TCP messages to the client program and waits for another command of the client.
The pulses are generated via an hardware card and are given on our application through a DLL who scans the INTERRUPT of this card.
Next to this, there are two threads in our application, one TCP Thread and one ARCNET thread. Next to these there are app. 14 other threads generated by Delphi components who we are using in other projects.
Now to the problem. After a certain time, the application comes into the state 'Not responding'. Windows is still working fine but the application needs to be closed down with Ctrl-Alt-Del. I've inserted logging in the application to see if it the threads aren't blocking each other but everything seems fine. To call a method from within the TCP thread or the ARCNET thread we use the synchronize methods.
When the application hangs, it is the main thread that is hanging. Can anyone help me futher with this problem??
Or can anyone advice me good tools to detect the problem better?? I'm stuck with this problem for several months now and don't see a solution yet, worse, I don't know where to search anymore....
So all help, tips, tools or other things I can use to search this problem are welcome.

Here is the code of the execute methods of the self-made threads :

THE ARCNET THREAD

procedure TAtsArcThread.Execute;
var
  bStop: boolean;
  msg: S1000Message;
  iLen: integer;
  hWnd: cardinal;
  iError: integer;
  lwait: ulong;
  i, read, write: integer;
  bVerwerkt: boolean;
  str: string;
  pmsg: pS1000Message;
  lSelectResult: integer;
  UsersOk: boolean;
begin
  bStop := false;
  iLen := sizeof(S1000Message);
  hWnd := 0;
  lWait := 0; // DN 061003  was 500
  read := 1;
  write := 1;

  while (not bStop) do
  begin
    try
      read := 0;

      lSelectResult := fArc.select(read, write, lWait);

      while read > 0 do
      begin
        read := read - 1;

        iError := farc.receive(msg, iLen);

        if (SMCOK = iError) then
        begin
          farc.a_bARCOk := true;
          i := 0;
          bVerwerkt := false;
          UsersOk := false;
          syncmsg := msg;
          synchronize(GotoMainThread);
==>GOING TO MAIN THREAD

        end
        else
        begin
          if not (farc.lasterror = SMCRECEIVEFAILED) then
          begin
            farc.a_bARCOk := false;
          end;
        end;
      end;

      read := 1;
      write := 1;

      // Controleer of thread moet stoppen
      bStop := (WAIT_OBJECT_0 = WaitForSingleObject(farc.e_hStop, 0));
      if bStop then
        templog(1, 'Arcnet thread gestopt!, (WAIT_OBJECT_0 = WaitForSingleObject(farc.e_hStop, 0)) = TRUE');

    except
      on E: Exception do
      begin
        templog(2, 'Arcnet thread exception : ' + E.Message);
        read := 1;
        write := 1;
      end;
    end;
  end;

 //Zo wordt de thread beter afgesloten
 //Geen int 3 breakpoint of memoryleaks meer
 //Moet zo ongeveer, duidelijk voorbeeld in de help ontbreekt natuurlijk weer
  PostQuitMessage(0);

end;



The GOTOMAINTHREAD METHOD FOR THIS THREAD (frmclockcontroller is the main thread) :

procedure TatsArcThread.GotoMainThread;
var
  i: integer;
  bVerwerkt: Boolean;
begin
  i := 0;
  bVerwerkt := false;
  while ((not bVerwerkt) and (i < CNSARCNET_MAXUSERS)) do
  begin
    if not (farc.a_arcUsers[i] = nil) then
    begin
      if ((S1000Message(Syncmsg).hdr.cmd = ARCCMD_KOOP) and (frmClockController.ClockEngine.ClockStatus = csClockTurningDown)) then
      begin
        ErIsGekocht := True;
        frmClockController.AddException('«SMCARC MAINTHREAD» ArcNet bericht KOOP');
      end
      else
        frmClockController.AddException('«SMCARC MAINTHREAD» ArcNet bericht ONBEKEND');
      bVerwerkt := farc.a_arcUsers[i].ThreadProc(Syncmsg);
    end;
    inc(i);
  end;
end;







THE TCP THREAD


procedure TVMT.TCPServerExecute(AThread: TIdPeerThread);
// Hier komt het bericht van de VMT (tcp/ip) binnen
begin
  try
    TCPConnectionThread := AThread;

    ClientIP := AThread.Connection.Socket.Binding.PeerIP;

    while AThread.Connection.Connected do
    begin
      VMTString := AThread.Connection.ReadLn('~', 10, -1);
      Athread.synchronize(GotoMainThread);

==> GOTO THE MAIN THREAD

    end;
  except
    on E: Exception do
      templog(2, 'TCPServerExecute Exception : ' + E.Message);
  end;
end;


THE GOTOMAINTHREAD EXECUTE METHOD FOR ABOVE THREAD


procedure TVMT.GotoMainThread;
var
i : Integer;
tempstring,temp : string;
begin
{$IFDEF DNVMT}
  vmtThread.AddMessage(VMTString);
{$ELSE}
temp := vmtstring;
tempstring:='';
for i:= 1 to length(temp) do
  tempstring:= tempstring + ' '+ inttostr(ord(temp[i]));
    frmClockController.AddException('«VMT MAINTHREAD» TCP ontvangen ' + tempstring);
  TranslateReceivedValue(VMTString);
==>TRANSLATERECEIVEVALUE IS A METHOD IN THE MAIN THREAD!!!
{$ENDIF}
end;
 
Related Solutions
Keywords: DELPHI APPLICATION HANGS AFTER …
 
Loading Advertisement...
 
[+][-]12/16/04 09:24 AM, ID: 12843076Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/16/04 11:17 PM, ID: 12848166Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/17/04 12:10 AM, ID: 12848364Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/17/04 12:10 AM, ID: 12848365Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/17/04 12:28 AM, ID: 12848459Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/17/04 01:43 PM, ID: 12854235Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/21/05 06:13 AM, ID: 13102399Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/21/05 06:39 AM, ID: 13102715Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Delphi Programming
Tags: delphi
Sign Up Now!
Solution Provided By: Madshi
Participating Experts: 4
Solution Grade: A
 
[+][-]02/01/05 07:45 AM, ID: 13193672Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02/25/05 12:30 AM, ID: 13400990Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]02/25/05 01:31 AM, ID: 13401321Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81