Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Thread safe inside DLL
Mon, Jun 11 2007 5:16 PMPermanent Link

"Jose Eduardo Helminsky"
Tim

If you record, I am building an application that holds DBISAM server and
another multi-thread server to run remote procedures. Each thread will load
a DLL and execute some actions. So far, so good. My doubt is: Should be the
procedures inside DLL thread safe ?

Eduardo

Tue, Jun 12 2007 3:30 PMPermanent Link

"Jose Eduardo Helminsky"
Tim

Forget it.
I´ve realized the code inside DLL MUST be thread safe because DLL is loaded
*INSIDE* a thread.

Eduardo

"Jose Eduardo Helminsky" <contato@hpro.com.br> escreveu na mensagem
news:A88AE53B-C41B-4ADB-A18D-19BE687E43A1@news.elevatesoft.com...
> Tim
>
> If you record, I am building an application that holds DBISAM server and
> another multi-thread server to run remote procedures. Each thread will
> load a DLL and execute some actions. So far, so good. My doubt is: Should
> be the procedures inside DLL thread safe ?
>
> Eduardo

Tue, Jun 12 2007 6:20 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Eduardo,

<< Forget it.  I´ve realized the code inside DLL MUST be thread safe because
DLL is loaded *INSIDE* a thread. >>

Loaded *and* executed inside a thread. Smiley

--
Tim Young
Elevate Software
www.elevatesoft.com

Wed, Jun 13 2007 8:53 AMPermanent Link

"Jose Eduardo Helminsky"
Tim

Another important thing that I realize after a day of tests is a need of
using IsMultiThread := True at DLL initialization because ALL the code were
thread safe but if I remove this line of code the server crashes.

library dbhpro;

uses FastMM4, SysUtils, rproc in 'rproc.pas';

function DisableThreadLibraryCalls(hLibModule: HMODULE): Boolean; stdcall;
external 'kernel32';

function Process(cAux: PChar): ShortString; stdcall;
begin
       // My routines
end;

exports Process;

begin
    IsMultiThread := True;                 <----------------- Needed by a
DLL loaded and executed inside a thread
    DisableThreadLibraryCalls(hInstance);
end.

Only to you know (if not) and others because I´ve spent a day googling to a
solution.

Eduardo

Wed, Jun 13 2007 4:05 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Eduardo,

<< Another important thing that I realize after a day of tests is a need of
using IsMultiThread := True at DLL initialization because ALL the code were
thread safe but if I remove this line of code the server crashes. >>

Yep.  We missed this early on in the ODBC driver and had the same issue.
It's very easy to miss when you're used to it auto-setting when you use the
built-in threading objects.

--
Tim Young
Elevate Software
www.elevatesoft.com

Image