[Lazarus] Callback and Threads problem

Leonardo M. Ramé l.rame at griensu.com
Fri Apr 6 14:31:40 CEST 2012


I have a similar problem to this:

http://www.lazarus.freepascal.org/index.php?topic=10571.0

My main program launches a thread, that loads a shared library, then
execute a function who receives as a parameter a pointer to a callback
function and an instance of the caller, as this:

procedure TMythread.execute;
begin
  ...
  // external function
  runcode(@MyCallBack, @Self);
  ...
end;

procedure MyCallback(const Result: PAnsiChar; const ACaller: pointer);
cdecl;
var
  lCaller: TMythread;
begin
  // the parameter ACaller is used because callbacks can't be of type
  // procedure of object.
  lCaller := TMyThread(ACaller);
  lCaller.TestVar := Result; // <--- Ok.
  lCaller.ListOfThings.Add;  // <--- SIGSEGV
  ...
end;

The problem is that every time I try to execute the method Add of a
TCollection or TObjectList I get a SIGSEGV. 

I must point out that the method "runcode" in the shared library is not
multithreaded. Also the shared library was linked against pthreads
library, and the main program uses cthreads. I also tried to enclose
the Callback inside a CriticalSection but the problem persists.

Thanks in advance,
-- 
Leonardo M. Ramé
Medical IT - Griensu S.A.
Av. Colón 636 - Piso 8 Of. A
X5000EPT -- Córdoba
Tel.: +54(351)4246924 +54(351)4247788 +54(351)4247979 int. 19
Cel.: +54(351)156629292





More information about the Lazarus mailing list