Subject Re: [firebird-support] how to implement thread safe UDFs ?
Author Martijn Tonies
Hi Kamlesh,

> what can be said the better way to implement thread safe UDFs ?
> can i make my functions thread safe by using CriticalSection in following
> manner ?
>
> // following is my UDF Library Unit
>
> unit MyUDFUnit;
>
> interface
> uses
> SysUtils, SyncObjs;
>
> Var
> FCriticalsection: TCriticalSection;
>
> implementation
>
> Procedure EnterFunction;
> Begin
> FCriticalsection.Enter;
> End;
>
> Procedure ExitFunction;
> Begin
> FCriticalsection.Leave;
> End;
>
> Function MyFunction(ACString:PChar):Integer; cdecl; export;
> Begin
> EnterFunction;
>
> // do some work here

If you don't use any global variables or global objects and
use thread-safe functions in your own function, it will be
thread-safe already. Or at least, according to me ;-)


> ExitFunction;
> End;
>
> exports
> MyFunction;
>
> Initialization
> FCriticalsection := TCriticalSection.Create;
> Finalization
> FCriticalsection.Free;
> End.


With regards,

Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com