Recent

Author Topic: (SOLVED) Linux + multithreaded application  (Read 10230 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
(SOLVED) Linux + multithreaded application
« on: July 19, 2012, 12:50:55 pm »
Hello guys, I have written multithreaded code that works on windows but on linux no. returns 'RunError(211)'. Why?


Project Statistiche raised exception class 'RunError(211)'.
« Last Edit: July 29, 2012, 02:03:24 pm by xinyiman »
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Linux + multithreaded application
« Reply #1 on: July 19, 2012, 01:00:52 pm »
Does your project source have this at that start of your uses clause?

Code: [Select]
program MyProgram;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
..
..
..

cdbc

  • Hero Member
  • *****
  • Posts: 2728
    • http://www.cdbc.dk
Re: Linux + multithreaded application
« Reply #2 on: July 19, 2012, 01:11:06 pm »
Hi

This works for me on linux:
Code: [Select]
program devsync;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}cthreads,{$ENDIF}
  Interfaces, // this includes the LCL widgetset
  Forms, lfm_main;

{$R *.res}

begin
  {$ifdef unix} RequireDerivedFormResource := True; {$endif}
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Linux + multithreaded application
« Reply #3 on: July 19, 2012, 01:36:09 pm »
Does your project source have this at that start of your uses clause?

Code: [Select]
program MyProgram;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
..
..
..

Yes

{$ifdef unix}
  cthreads,
  cmem, // the c memory manager is on some systems much faster for multi-threading
{$endif}
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Linux + multithreaded application
« Reply #4 on: July 24, 2012, 08:14:34 am »
My example for replicate error:
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Linux + multithreaded application
« Reply #5 on: July 25, 2012, 12:58:10 pm »
Help please!
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Blestan

  • Sr. Member
  • ****
  • Posts: 461
Re: Linux + multithreaded application
« Reply #6 on: July 25, 2012, 02:11:55 pm »
Hi!
First enclose the critical section enter / leave in a try finally block!!!

try
 enter cs

finally

 leave cs

second ...

create the treads in SUSPENDED state!!!! this is crucial!!!

the create (init of the thread object data ) code is executed in   main thread and the thread start to execute BEFORE the init is done ...

so you must first do a
thread.create(true)
then thread.start



Speak postscript or die!
Translate to pdf and live!

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Linux + multithreaded application
« Reply #7 on: July 25, 2012, 02:34:42 pm »
So simple: you don't have -dUseCThreads in the compiler options (Other->Custom Options).

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Linux + multithreaded application
« Reply #8 on: July 27, 2012, 12:40:59 pm »
So simple: you don't have -dUseCThreads in the compiler options (Other->Custom Options).

Thank you :)

Now it only works when I close the application I get:

Project projectMT raised exception class 'External: SIGABRT'.

Why?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Linux + multithreaded application
« Reply #9 on: July 29, 2012, 02:02:20 pm »
Solved! I change

  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}         

with

  {$ifdef unix}
    cthreads,
    cmem, // the c memory manager is on some systems much faster for multi-threading
  {$endif}

into *.lpr file
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

 

TinyPortal © 2005-2018