Shared library - segfaults in multithread environment
Original Reporter info from Mantis: jakubklos
-
Reporter name: Jakub Klos - IceWarp
Original Reporter info from Mantis: jakubklos
- Reporter name: Jakub Klos - IceWarp
Description:
A shared library called from the main program crashes with segfault if the library creates threads. The main program calls the library from several threads and it all works until the library creates its own first thread.
After the creation of the first library thread the next call to the library from a new thread segfaults.
A complete explanation can be found in the additional information section.
Reproduced on multiple linux distributions, tried 2.0.2 and 2.3.1 versions.
Might be a RTL or compiler's bug itself. I even tried to compile the Classes and CThreads libraries to see what is going on and it's not clear to me.
All is fine until the LThread.Execute is called. It needs to be debugged.
I can help to fix this issue.
Thank you
Jakub
Additional information:
I created 2 very simple projects
One main application that loads a library and creates 2 threads which each call a function from the library.
The library itself in the function create a new thread again. All cases write something to the output.
Error: Once the library creates a thread, subsequent calls to the library from other threads from the main application segfault and crash.
Source peek:
testx.pp:
Uses CThreads, Classes, SysUtils, dynlibs;
Var
XTest: Procedure;
Type
TE = Class(TThread)
Procedure Execute; Override;
End;
Procedure TE.Execute;
Begin
FreeOnTerminate := True;
Writeln('Main begin');
XTest;
Writeln('Main end');
End;
Var
FH: Longint;
Begin
// Load library
FH := LoadLibrary('./libtestlib.so');
XTest := GetProcAddress(FH, 'Test');
// Create threads
TE.Create(False);
Sleep(200);
TE.Create(False);
Readln;
End.
testlib.pp:
Library testlib;
Uses CThreads, Classes;
Type
TE = Class(TThread)
Procedure Execute; Override;
End;
Procedure TE.Execute;
Begin
FreeOnTerminate := True;
Writeln('Execute');
End;
Procedure Test;
Begin
// Writeln
Writeln('Test');
// Create thread
TE.Create(False);
End;
Exports
Test;
End.
Mantis conversion info:
- Mantis ID: 8623
- Version: 2.3.1
- Fixed in version: 2.4.0
- Monitored by: » werner.bochtler@zkrd.de (Werner Bochtler)