Difference between revisions of "Talk:Multithreaded Application Tutorial"

From Free Pascal wiki
Jump to navigationJump to search
 
(9 intermediate revisions by 4 users not shown)
Line 1: Line 1:
procedure TMyThread.Execute;
+
== fpc_popaddrstack() ==
  var
 
    newStatus : string;
 
  begin
 
    fStatusText := 'TMyThread Starting...';
 
    Synchronize(@Showstatus);
 
    fStatusText := 'TMyThread Running...';
 
  
this is a
+
I want to use FPC to compile my WinApi multi-threaded application but after compilation and running I often receive SIGSEGV error. After debugging, the segmentation fault is ALWAYS in function "fpc_popaddrstack()".  
very good example of what you should NEVER do..
 
  
Showstatus will NEVER display the text 'TMyThread Starting...';
+
The application uses hooks and CreateRemoteThread. Thus additional calls to "fpc_popaddrstack()" must not be made. The trick described in that article will not work properly. These calls shall be disabled.
  
will show "TMyThread Running..."
+
I do not use "try-except" and "try-finally" blocks in my code and I don't need exception handling.
maybe twice ...
+
My question is: '''How to supress the fpc_popaddrstack() or (better) all routines in unit "except.inc"?''' (any directive to disable it)
  
change your main-thread code to:
+
I will be very grateful for a solution to my problem.
 +
[[User:Xena|Xena]] 00:37, 16 February 2014 (CET)
  
  procedure TForm1.ShowStatus(Status: string);
+
== fpgui ==
  begin
 
    memo1.Lines.Add(Status);
 
  end;
 
  
 +
I rewrote the example as an fpgui program (just for my own education).
 +
I don't know whether this is useful to anyone else.
 +
Anyway, find the example here
 +
http://forum.lazarus.freepascal.org/index.php/topic,24217.0.html : [[User:Dieselnutjob|dieselnutjob]]
  
and you will see what i mean..
+
== Unfortunate sample code ==
  
 +
The code sample given in "The TThread Class" is IMHO not very good.
  
second bad thing:
+
The line fStatusText := 'TMyThread Running...'; has no effect, no call to synchronize appears, and the text will never be displayed. There is also a mixup of programming strategies because at one time the author assigns to FStatusText, then he assigns to NewStatus, all for the same outcome. I'd like to slightly change the sample and put the FStatusText assignment and the call to synchronize into a setter of a property "Status", which is, IMHO, a far better implementation beeing more readable and avoiding those kind of errors alltogether.
 
  procedure TMyThread.ShowStatus;
 
  // this method is executed by the mainthread and can therefore access all GUI elements.
 
  begin
 
    if Assigned(FOnShowStatus) then
 
    begin
 
      FOnShowStatus(fStatusText);
 
    end;
 
  end;
 
  
 
+
May I?
as you can read: it is es executed by mainthread!!
 
 
 
you are accessing fStatusText from the mainthread and the thread (in worst case, at the same time, )
 
 
 
so using a critical section, would be good..
 

Latest revision as of 11:27, 24 January 2022

fpc_popaddrstack()

I want to use FPC to compile my WinApi multi-threaded application but after compilation and running I often receive SIGSEGV error. After debugging, the segmentation fault is ALWAYS in function "fpc_popaddrstack()".

The application uses hooks and CreateRemoteThread. Thus additional calls to "fpc_popaddrstack()" must not be made. The trick described in that article will not work properly. These calls shall be disabled.

I do not use "try-except" and "try-finally" blocks in my code and I don't need exception handling. My question is: How to supress the fpc_popaddrstack() or (better) all routines in unit "except.inc"? (any directive to disable it)

I will be very grateful for a solution to my problem. Xena 00:37, 16 February 2014 (CET)

fpgui

I rewrote the example as an fpgui program (just for my own education). I don't know whether this is useful to anyone else. Anyway, find the example here http://forum.lazarus.freepascal.org/index.php/topic,24217.0.html : dieselnutjob

Unfortunate sample code

The code sample given in "The TThread Class" is IMHO not very good.

The line fStatusText := 'TMyThread Running...'; has no effect, no call to synchronize appears, and the text will never be displayed. There is also a mixup of programming strategies because at one time the author assigns to FStatusText, then he assigns to NewStatus, all for the same outcome. I'd like to slightly change the sample and put the FStatusText assignment and the call to synchronize into a setter of a property "Status", which is, IMHO, a far better implementation beeing more readable and avoiding those kind of errors alltogether.

May I?